Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ name: Test

on:
push:
branches: [master]
branches: [master, tre]
pull_request:
branches: [master]
branches: [master, tre]

jobs:
test:
Expand All @@ -18,14 +18,14 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [16.13.0, 18.x]
os: [ubuntu-latest] # `windows-latest` not yet supported
node: [16.13.0, latest]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm ci
Expand All @@ -35,11 +35,11 @@ jobs:
name: "Lint & Type Check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 18.x
uses: actions/setup-node@v2
- uses: actions/checkout@v3
- name: Use Node.js LTS
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: lts/*
- run: npm ci
- run: npm run lint
- run: npm run types:build
- run: npm run types:bundle
1 change: 0 additions & 1 deletion ava.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const rewritePaths = Object.fromEntries(

export default {
files: ["packages/*/test/**/*.spec.ts"],
timeout: "5m",
nodeArguments: ["--no-warnings", "--experimental-vm-modules"],
typescript: {
compile: false,
Expand Down
13 changes: 8 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"packages/*"
],
"scripts": {
"postinstall": "patch-package",
"build": "node scripts/build.mjs",
"capnp:workerd": "capnpc -o ts packages/tre/src/runtime/config/workerd.capnp",
"clean": "rimraf './packages/*/dist' './dist'",
Expand Down Expand Up @@ -60,6 +61,6 @@
"node": ">=16.13"
},
"volta": {
"node": "18.2.0"
"node": "16.13.0"
}
}
2 changes: 1 addition & 1 deletion packages/tre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"workerd": "^1.20230221.0",
"ws": "^8.11.0",
"youch": "^3.2.2",
"zod": "^3.18.0"
"zod": "^3.20.6"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/tre/src/plugins/cache/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Headers, HeadersInit, Request, Response, fetch } from "../../http";
import { Clock, Log, millisToSeconds } from "../../shared";
import { Storage } from "../../storage";
import { isSitesRequest } from "../kv";
import { _getRangeResponse } from "../shared";
import { CacheMiss, PurgeFailure, StorageFailure } from "./errors";
import { _getRangeResponse } from "./range";

interface CacheMetadata {
headers: string[][];
Expand Down
1 change: 0 additions & 1 deletion packages/tre/src/plugins/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,3 @@ export const CACHE_PLUGIN: Plugin<
};

export * from "./gateway";
export * from "./range";
39 changes: 23 additions & 16 deletions packages/tre/src/plugins/r2/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Response } from "../../http";
import { HttpError } from "../../shared";
import { CfHeader } from "../shared/constants";
import { R2Object } from "./r2Object";

Expand All @@ -13,7 +14,7 @@ enum CfCode {
InternalError = 10001,
NoSuchObjectKey = 10007,
EntityTooLarge = 100100,
InvalidDigest = 10014,
MetadataTooLarge = 10012,
InvalidObjectName = 10020,
InvalidMaxKeys = 10022,
InvalidArgument = 10029,
Expand All @@ -22,22 +23,18 @@ enum CfCode {
InvalidRange = 10039,
}

export class R2Error extends Error {
status: number;
v4Code: number;
export class R2Error extends HttpError {
object?: R2Object;
constructor(status: number, message: string, v4Code: number) {
super(message);
this.name = "R2Error";
this.status = status;
this.v4Code = v4Code;

constructor(code: number, message: string, readonly v4Code: number) {
super(code, message);
}

toResponse() {
if (this.object !== undefined) {
const { metadataSize, value } = this.object.encode();
return new Response(value, {
status: this.status,
status: this.code,
headers: {
[CfHeader.MetadataSize]: `${metadataSize}`,
"Content-Type": "application/json",
Expand All @@ -51,7 +48,7 @@ export class R2Error extends Error {
});
}
return new Response(null, {
status: this.status,
status: this.code,
headers: {
[CfHeader.Error]: JSON.stringify({
message: this.message,
Expand Down Expand Up @@ -113,21 +110,31 @@ export class EntityTooLarge extends R2Error {
}
}

export class InvalidDigest extends R2Error {
export class MetadataTooLarge extends R2Error {
constructor() {
super(
Status.BadRequest,
"The Content-MD5 you specified is not valid.",
CfCode.InvalidDigest
"Your metadata headers exceed the maximum allowed metadata size.",
CfCode.MetadataTooLarge
);
}
}

export class BadDigest extends R2Error {
constructor() {
constructor(
algorithm: "MD5" | "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512",
provided: Buffer,
calculated: Buffer
) {
super(
Status.BadRequest,
"The Content-MD5 you specified did not match what we received.",
[
`The ${algorithm} checksum you specified did not match what we received.`,
`You provided a ${algorithm} checksum with value: ${provided.toString(
"hex"
)}`,
`Actual ${algorithm} was: ${calculated.toString("hex")}`,
].join("\n"),
CfCode.BadDigest
);
}
Expand Down
Loading