Avoid Sentry reporting of selected common "expected" errors

Change-type: patch
This commit is contained in:
Paulo Castro 2020-03-05 01:02:46 +00:00
parent d2df2c7b60
commit 5a80654305
2 changed files with 17 additions and 6 deletions

View File

@ -17,8 +17,9 @@ limitations under the License.
import { stripIndent } from 'common-tags'; import { stripIndent } from 'common-tags';
import * as _ from 'lodash'; import * as _ from 'lodash';
import * as os from 'os'; import * as os from 'os';
import { TypedError } from 'typed-error';
export class ExpectedError extends Error {} export class ExpectedError extends TypedError {}
export class NotLoggedInError extends ExpectedError {} export class NotLoggedInError extends ExpectedError {}
@ -115,7 +116,17 @@ export async function handleError(error: any) {
} }
printErrorMessage(message.join('\n')); printErrorMessage(message.join('\n'));
if (error instanceof ExpectedError) { const expectedErrorREs = [
/^BalenaApplicationNotFound:/, // balena-sdk
/^BalenaDeviceNotFound:/, // balena-sdk
/^Missing \w+$/, // Capitano's command line parsing error
/^Unexpected arguments?:/, // oclif's command line parsing error
];
if (
error instanceof ExpectedError ||
expectedErrorREs.some(re => re.test(message[0]))
) {
return; return;
} }

View File

@ -22,12 +22,12 @@ import { RegistrySecrets } from 'resin-multibuild';
import * as Stream from 'stream'; import * as Stream from 'stream';
import streamToPromise = require('stream-to-promise'); import streamToPromise = require('stream-to-promise');
import { Pack } from 'tar-stream'; import { Pack } from 'tar-stream';
import { TypedError } from 'typed-error';
import Logger = require('./logger');
import { ExpectedError } from '../errors';
import { exitWithExpectedError } from '../utils/patterns'; import { exitWithExpectedError } from '../utils/patterns';
import { tarDirectory } from './compose'; import { tarDirectory } from './compose';
import { getVisuals } from './lazy'; import { getVisuals } from './lazy';
import Logger = require('./logger');
const globalLogger = Logger.getLogger(); const globalLogger = Logger.getLogger();
@ -77,7 +77,7 @@ interface HeadlessBuilderMessage {
releaseId?: number; releaseId?: number;
} }
export class RemoteBuildFailedError extends TypedError { export class RemoteBuildFailedError extends ExpectedError {
public constructor(message = 'Remote build failed') { public constructor(message = 'Remote build failed') {
super(message); super(message);
} }
@ -138,10 +138,10 @@ export async function startRemoteBuild(build: RemoteBuild): Promise<void> {
stream.on('end', resolve); stream.on('end', resolve);
stream.on('error', reject); stream.on('error', reject);
}).then(() => { }).then(() => {
globalLogger.outputDeferredMessages();
if (build.hadError) { if (build.hadError) {
throw new RemoteBuildFailedError(); throw new RemoteBuildFailedError();
} }
globalLogger.outputDeferredMessages();
}); });
} }