Skip to content
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
9 changes: 2 additions & 7 deletions app/backend/src/acceptVisualChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,15 @@ export const acceptVisualChanges = async ({
throw new TRPCError({
code: 'FORBIDDEN',
message: reasonToPreventUpdate,
cause: {
event: 'VISUAL_CHANGE_ACCEPTANCE_BLOCKED',
owner,
repo,
commitHash
}
cause: 'VISUAL_CHANGE_ACCEPTANCE_BLOCKED'
});
}
const hash = commitHash ?? diffId;
if (!hash) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Please provide either a commitHash or a diffId.',
cause: { event: 'MISSING_IDENTIFIER', owner, repo }
cause: 'MISSING_IDENTIFIER'
});
}

Expand Down
10 changes: 2 additions & 8 deletions app/backend/src/fetchCurrentPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ export const fetchCurrentPage = async ({
throw new TRPCError({
code: 'NOT_FOUND',
message: `Page ${page} does not exist. Only ${paginatedKeys.length} pages were found.`,
cause: {
event: 'PAGE_NOT_FOUND',
hash,
bucket,
page,
totalPages: paginatedKeys.length
}
cause: 'PAGE_NOT_FOUND'
});
}
const { keys, title } = currentPage;
Expand All @@ -32,7 +26,7 @@ export const fetchCurrentPage = async ({
throw new TRPCError({
code: 'BAD_REQUEST',
message: `Invalid file name: ${key}. ${result.error.message}`,
cause: { event: 'INVALID_FILE_NAME', hash, bucket, key }
cause: 'INVALID_FILE_NAME'
});
}

Expand Down
4 changes: 2 additions & 2 deletions app/backend/src/getGroupedKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getGroupedKeys = async (hash: string, bucket: string) => {
code: 'NOT_FOUND',
message:
'The commit hash was not associated with any visual regression test failures.',
cause: { event: 'COMMIT_HASH_NOT_FOUND', hash, bucket }
cause: 'COMMIT_HASH_NOT_FOUND'
});
}

Expand All @@ -36,7 +36,7 @@ export const getGroupedKeys = async (hash: string, bucket: string) => {
code: 'NOT_FOUND',
message:
'There was no new or diff images associated with the commit hash.\nThis might be because the tests failed before a screenshot could be taken and it could be compared to the base.',
cause: { event: 'NO_NEW_OR_DIFF_IMAGES', hash, bucket }
cause: 'NO_NEW_OR_DIFF_IMAGES'
});
}

Expand Down
6 changes: 3 additions & 3 deletions app/backend/src/getOctokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getOctokit = (owner: string, repo: string) => {
throw new TRPCError({
code: 'UNAUTHORIZED',
message: 'Missing secrets.json file',
cause: { event: 'MISSING_SECRETS_FILE', owner, repo, secretsFilePath }
cause: 'MISSING_SECRETS_FILE'
});
}
const parsedJson = JSON.parse(readFileSync(secretsFilePath).toString());
Expand All @@ -18,7 +18,7 @@ export const getOctokit = (owner: string, repo: string) => {
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: `Failed to parse secrets.json: ${result.error}`,
cause: { event: 'SECRETS_PARSE_ERROR', owner, repo, error: result.error }
cause: 'SECRETS_PARSE_ERROR'
});
}
const repoSecrets = result.data[`${owner}/${repo}`];
Expand All @@ -27,7 +27,7 @@ export const getOctokit = (owner: string, repo: string) => {
throw new TRPCError({
code: 'UNAUTHORIZED',
message: `Missing githubToken for repo ${owner}/${repo}`,
cause: { event: 'MISSING_GITHUB_TOKEN', owner, repo }
cause: 'MISSING_GITHUB_TOKEN'
});
}
return new Octokit({
Expand Down
8 changes: 1 addition & 7 deletions app/backend/src/updateCommitStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ export const updateCommitStatus = async ({
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: `Failed to update GitHub commit status: ${error}`,
cause: {
event: 'COMMIT_STATUS_UPDATE_FAILED',
owner,
repo,
commitHash,
error
}
cause: 'COMMIT_STATUS_UPDATE_FAILED'
});
});
};
16 changes: 6 additions & 10 deletions app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ const DIST_DIR = join(import.meta.dir, 'dist');
const trpcHandler = createBunHttpHandler({
router,
endpoint: '/trpc',
onError: ({ error: { code, message, cause }, path }) => {
const event =
cause && 'event' in cause && typeof cause.event === 'string'
? cause.event
: 'UNKNOWN';
const causeWithEvent = {
...cause,
event
};
logEvent('ERROR', { path, code, message, cause: causeWithEvent });
onError: ({ error: { code, message, cause }, path, req }) => {
const referer = req.headers.get('referer');
const urlParams = referer
? Object.fromEntries(new URL(referer).searchParams)
: {};
logEvent('ERROR', { path, code, message, cause, ...urlParams });
}
});

Expand Down
Loading