Skip to content

Commit

Permalink
fix: improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kathikraemer authored and Jumace committed Mar 14, 2024
1 parent f28a6b8 commit 31e23a8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/metrics/commits-per-pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export const collectCommitsPerPrMetrics = async (
repo: repo,
pull_number: payload.pull_request.number,
})
.catch(() => {
.catch((error: unknown) => {
status = "networkError";
logger.error(LogErrors.networkErrorCommitsPerPR, prId);
logger.error(LogErrors.networkErrorCommitsPerPR, prId, error);
return null;
});

Expand Down
5 changes: 3 additions & 2 deletions src/metrics/deployments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ export const collectDeploymentMetrics = async (
repo: repo,
environment: env,
})
.catch(() => {
.catch((error: unknown) => {
status = "networkError";
logger.error(
LogErrors.networkErrorDeployments,
`${owner}/${repo}/${env}`
`${owner}/${repo}/${env}`,
error
);
return null;
});
Expand Down
7 changes: 5 additions & 2 deletions src/metrics/release-versions/get-version-by-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { SemVer, clean as semverClean, parse as semverParse } from "semver";
import { ReleaseVersion } from "./interfaces";
import { LogErrors } from "../../shared/log-messages";
import pick from "lodash.pick";
import { ErrorForLogger, ErrorLevel } from "../../core/error-logger";

export const getVersionByString = (ref: string): ReleaseVersion => {
const version: SemVer | null = semverParse(semverClean(ref, { loose: true }));
if (version === null) {
// this error should already be caught by the metric condition and type check of the metric itself
throw new Error(
`${LogErrors.releaseVersionsUnexpectedInvalidVersion}: ${ref}`
throw new ErrorForLogger(
ErrorLevel.Error,
LogErrors.releaseVersionsUnexpectedInvalidVersion,
ref
);
}

Expand Down
10 changes: 3 additions & 7 deletions src/shared/log-messages.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
export enum LogErrors {
collectMetricsSignatureNotRecognized = "No collect-metrics function found for this event.",
wrongResolvedEnhancedEvents = "Enhanced Events are invalid.",
networkErrorCommitsPerPR = "Could not fetch commits for PR-Id: '%s'",
networkErrorDeployments = "Could not fetch deployments for owner/repo/env: '%s'",
networkErrorCommitsPerPR = "Could not fetch commits for PR-Id: '%s'\nError: %s",
networkErrorDeployments = "Could not fetch deployments for owner/repo/env: '%s'\nError: %s",
networkErrorPackageJson = "Could not fetch package.json for owner/repo: '%s'",
networkErrorDocumentationSkeletonConfig = "Could not fetch documentation-skeleton-config.json for owner/repo: '%s'",
releaseVersionsUnexpectedInvalidVersion = "Unexpected invalid Release Version",
releaseVersionsUnexpectedInvalidVersion = "Unexpected invalid Release Version: %s",
genericServerError = "Server Error - Check the logs",
couldNotStoreData = "The following data could not be stored (see previous logs for detailed errors): '%s'",
envVarRequired = "Required environment variable is not set: '%s'",
envVarNotANumber = "Environment variable is set but not parsable as an integer: '%s'",
envVarUnsafeInt = "Environment variable is set but not parsable as a safe integer: '%s'",
Expand All @@ -18,7 +15,6 @@ export enum LogErrors {
export enum LogInfos {
eventReceived = "Received '%s' event",
eventSigned = "Event has been signed as: '%s'",
startCollectingMetrics = "Trying to collect metrics...",
storeDataCheckingHead = "Store data failed, but we may try again. Fetching repo HEAD to check if we should retry storing data…",
storeDataRetrying = "HEAD of data repo changed, retrying to store data...",
}
Expand Down

0 comments on commit 31e23a8

Please sign in to comment.