diff --git a/packages/init/src/lib/setupSentry.ts b/packages/init/src/lib/setupSentry.ts index c35f7a5df9..578429f224 100644 --- a/packages/init/src/lib/setupSentry.ts +++ b/packages/init/src/lib/setupSentry.ts @@ -19,8 +19,8 @@ export function setupSentry(): void { environment: isStableVersion ? import.meta.env.MODE || "production" : "alpha", - // Increase the default truncation length of 250 to 2500 (x10) + // Increase the default truncation length of 250 to 12500 (x50) // to have enough details in Sentry - maxValueLength: 2_500, + maxValueLength: 12_500, }); } diff --git a/packages/init/src/lib/updateSentryContext.ts b/packages/init/src/lib/updateSentryContext.ts index 1b7a4d028b..55fb8981dc 100644 --- a/packages/init/src/lib/updateSentryContext.ts +++ b/packages/init/src/lib/updateSentryContext.ts @@ -39,4 +39,9 @@ export async function updateSentryContext({ if (framework) { Sentry.setTag("framework", framework); } + + Sentry.setContext("Process", { + "Command used": process.argv.join(" "), + cwd: process.cwd(), + }); } diff --git a/packages/manager/src/auth/PrismicAuthManager.ts b/packages/manager/src/auth/PrismicAuthManager.ts index c06620bffe..cdc6bd55ae 100644 --- a/packages/manager/src/auth/PrismicAuthManager.ts +++ b/packages/manager/src/auth/PrismicAuthManager.ts @@ -295,7 +295,9 @@ export class PrismicAuthManager { await this._writePersistedAuthState(authState); } else { - throw new InternalError("Failed to refresh authentication token."); + throw new InternalError("Failed to refresh authentication token.", { + cause: text, + }); } } else { throw new UnauthenticatedError(); @@ -320,9 +322,9 @@ export class PrismicAuthManager { "User-Agent": SLICE_MACHINE_USER_AGENT, }, }); - const json = await res.json(); if (res.ok) { + const json = await res.json(); const { value: profile, error } = decode(PrismicUserProfile, json); if (error) { @@ -333,8 +335,12 @@ export class PrismicAuthManager { return profile; } else { + const text = await res.text(); throw new InternalError( "Failed to retrieve profile from the Prismic user service.", + { + cause: text, + }, ); } } diff --git a/packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts b/packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts index 14383c20bc..2a36675f5e 100644 --- a/packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts +++ b/packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts @@ -45,7 +45,10 @@ const fetchAllGitHubReleases = async ( return value; } else { - throw new Error(`Invalid GitHub Release response.`); + const text = await res.text(); + throw new Error(`Invalid GitHub Release response.`, { + cause: text, + }); } }; diff --git a/packages/manager/src/lib/installDependencies.ts b/packages/manager/src/lib/installDependencies.ts index 507126cd81..b239b9f326 100644 --- a/packages/manager/src/lib/installDependencies.ts +++ b/packages/manager/src/lib/installDependencies.ts @@ -45,6 +45,12 @@ export const installDependencies = async ( if (!command) { throw new Error( "Failed to begin dependency installation (could not parse command)", + { + cause: { + packageManager: args.packageManager, + dependencies: args.dependencies, + }, + }, ); } diff --git a/packages/manager/src/managers/customTypes/CustomTypesManager.ts b/packages/manager/src/managers/customTypes/CustomTypesManager.ts index 489415a85a..bf3eaf0f03 100644 --- a/packages/manager/src/managers/customTypes/CustomTypesManager.ts +++ b/packages/manager/src/managers/customTypes/CustomTypesManager.ts @@ -252,6 +252,9 @@ export class CustomTypesManager extends BaseManager { } else if (error instanceof prismicCustomTypesClient.ForbiddenError) { throw new UnauthorizedError( "You do not have access to push types to this Prismic repository.", + { + cause: error, + }, ); } else { throw error; diff --git a/packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts b/packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts index d876482828..0dfcda52be 100644 --- a/packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts +++ b/packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts @@ -65,9 +65,9 @@ export class PrismicRepositoryManager extends BaseManager { async readAll(): Promise { const url = new URL("./repositories", API_ENDPOINTS.PrismicUser); const res = await this._fetch({ url }); - const json = await res.json(); if (res.ok) { + const json = await res.json(); const { value: repositories, error } = decode( t.array(PrismicRepository), json, @@ -81,7 +81,8 @@ export class PrismicRepositoryManager extends BaseManager { return repositories; } else { - throw new Error(`Failed to read repositories`, { cause: json }); + const text = await res.text(); + throw new Error(`Failed to read repositories`, { cause: text }); } } @@ -413,7 +414,9 @@ export class PrismicRepositoryManager extends BaseManager { const text = await response.text(); throw new Error(text); default: - throw new Error(`Unexpected status code ${response.status}`); + throw new Error(`Unexpected status code ${response.status}`, { + cause: await response.text(), + }); } } catch (err) { console.error("An error happened while pushing your changes"); diff --git a/packages/manager/src/managers/project/ProjectManager.ts b/packages/manager/src/managers/project/ProjectManager.ts index 8409ed9e16..0168b9bb75 100644 --- a/packages/manager/src/managers/project/ProjectManager.ts +++ b/packages/manager/src/managers/project/ProjectManager.ts @@ -173,7 +173,9 @@ export class ProjectManager extends BaseManager { if (error) { // TODO: Write a more friendly and useful message. - throw new Error(`Invalid config. ${error.errors.join(", ")}`); + throw new Error(`Invalid config. ${error.errors.join(", ")}`, { + cause: { rawConfig }, + }); } // Allow cached config reading using `SliceMachineManager.prototype.getProjectConfig()`. diff --git a/packages/manager/src/managers/screenshots/ScreenshotsManager.ts b/packages/manager/src/managers/screenshots/ScreenshotsManager.ts index 25f222eaa1..fb1f2bdcdd 100644 --- a/packages/manager/src/managers/screenshots/ScreenshotsManager.ts +++ b/packages/manager/src/managers/screenshots/ScreenshotsManager.ts @@ -140,6 +140,9 @@ export class ScreenshotsManager extends BaseManager { // Response is not JSON throw new Error( `Invalid AWS ACL response from ${awsACLURL}: ${awsACLText}`, + { + cause: error, + }, ); } @@ -162,12 +165,16 @@ export class ScreenshotsManager extends BaseManager { ); if (error) { - throw new Error(`Invalid AWS ACL response from ${awsACLURL}`); + throw new Error(`Invalid AWS ACL response from ${awsACLURL}`, { + cause: error, + }); } const errorMessage = awsACL.error || awsACL.message || awsACL.Message; if (errorMessage) { - throw new Error(`Failed to create an AWS ACL: ${errorMessage}`); + throw new Error(`Failed to create an AWS ACL: ${errorMessage}`, { + cause: error, + }); } this._s3ACL = { @@ -302,8 +309,12 @@ export class ScreenshotsManager extends BaseManager { url: url.toString(), }; } else { + const text = await res.text(); throw new Error( `Unable to upload screenshot with status code: ${res.status}`, + { + cause: text, + }, ); } } @@ -319,8 +330,12 @@ export class ScreenshotsManager extends BaseManager { url: new URL("delete-folder", API_ENDPOINTS.AwsAclProvider), }); if (!res.ok) { + const text = await res.text(); throw new Error( `Unable to delete screenshot folder with status code: ${res.status}`, + { + cause: text, + }, ); } } diff --git a/packages/start-slicemachine/src/lib/sentryErrorHandlers.ts b/packages/start-slicemachine/src/lib/sentryErrorHandlers.ts index 778665076a..de3aa9fde0 100644 --- a/packages/start-slicemachine/src/lib/sentryErrorHandlers.ts +++ b/packages/start-slicemachine/src/lib/sentryErrorHandlers.ts @@ -9,7 +9,9 @@ export const node = (name: string, error: unknown): void => { if (checkIsSentryEnabled()) { Sentry.withScope(function (scope) { scope.setTransactionName(name); - Sentry.captureException(error); + Sentry.captureException(error, { + ...(error instanceof Error ? { extra: { cause: error.cause } } : {}), + }); }); } }; diff --git a/packages/start-slicemachine/src/lib/setupSentry.ts b/packages/start-slicemachine/src/lib/setupSentry.ts index dec6851aba..70cc80f4a7 100644 --- a/packages/start-slicemachine/src/lib/setupSentry.ts +++ b/packages/start-slicemachine/src/lib/setupSentry.ts @@ -34,6 +34,9 @@ export const setupSentry = async ( environment: isStableVersion ? import.meta.env.MODE || "production" : "alpha", + // Increase the default truncation length of 250 to 12500 (x50) + // to have enough details in Sentry + maxValueLength: 12_500, }); if (userProfile) { Sentry.setUser({ id: userProfile.shortId });