Throw diagnostic when an argument doesn't match any files, add helper to throw a single diagnostic
MODIFY
packages/@romejs/core/client/commands.ts
packages/@romejs/core/client/commands.ts
@@ -10,7 +10,10 @@ import ClientRequest from './ClientRequest';
import {LocalCommand} from '../commands';
import {commandCategories} from '../commands';
import executeMain from '../common/utils/executeMain';
-import {DiagnosticsError} from '@romejs/diagnostics';
+import {
+ DiagnosticsError,
+ createSingleDiagnosticError,
+} from '@romejs/diagnostics';
import {createAbsoluteFilePath} from '@romejs/path';
import {Dict} from '@romejs/typescript-helpers';
import {writeFile} from '@romejs/fs';
@@ -198,7 +201,7 @@ localCommands.set('run', {
sourceMap: data.get('map').asAny(),
});
if (syntaxError !== undefined) {
- throw new DiagnosticsError(syntaxError.message, [syntaxError]);
+ throw createSingleDiagnosticError(syntaxError);
}
await new Promise(() => {});
break;

MODIFY
packages/@romejs/core/master/MasterRequest.ts
packages/@romejs/core/master/MasterRequest.ts
@@ -15,6 +15,7 @@ import {
getDiagnosticsFromError,
DiagnosticOrigin,
PartialDiagnosticAdvice,
+ createSingleDiagnosticError,
} from '@romejs/diagnostics';
import {DiagnosticsPrinterFlags} from '@romejs/cli-diagnostics';
import {ProjectDefinition} from '@romejs/project';
@@ -198,15 +199,13 @@ export default class MasterRequest {
advice?: PartialDiagnosticAdvice,
) {
const pointer = this.getDiagnosticPointerFromFlags(target);
- throw new DiagnosticsError(message, [
- {
+ throw createSingleDiagnosticError({
message,
filename: 'argv',
- category: 'error',
+ category: 'flags',
...pointer,
advice,
- },
- ]);
+ });
}
getDiagnosticPointerForClientCwd(): DiagnosticPointer {
@@ -313,6 +312,15 @@ export default class MasterRequest {
ignore: projectIgnore,
extensions,
});
+
+ if (matches.size === 0) {
+ throw createSingleDiagnosticError({
+ ...pointer,
+ category: 'flags',
+ message: 'No files found',
+ });
+ }
+
for (const path of matches) {
paths.add(path);
}

MODIFY
packages/@romejs/core/master/fs/resolverSuggest.ts
packages/@romejs/core/master/fs/resolverSuggest.ts
@@ -15,9 +15,9 @@ import Resolver, {
ResolverRemoteQuery,
} from './Resolver';
import {
- DiagnosticsError,
PartialDiagnosticAdvice,
buildSuggestionAdvice,
+ createSingleDiagnosticError,
} from '@romejs/diagnostics';
import {orderBySimilarity} from '@romejs/string-utils';
import {createUnknownFilePath, AbsoluteFilePath} from '@romejs/path';
@@ -233,20 +233,12 @@ export default function resolverSuggest(
message += ` <emphasis>${source}</emphasis> from <filelink emphasis target="${pointer.filename}" />`;
- throw new DiagnosticsError(errMsg, [
- {
- // TODO very confused by the usage of pointer and then querySource.pointer
+ throw createSingleDiagnosticError({
+ ...pointer,
category: 'resolver',
- filename: pointer.filename,
- start: pointer.start,
- end: pointer.end,
- sourceText: querySource.pointer.sourceText,
- language: querySource.pointer.language,
- mtime: querySource.pointer.mtime,
message,
advice,
- },
- ]);
+ });
}
type Suggestions = Map<string, string>;

MODIFY
packages/@romejs/core/master/project/ProjectManager.ts
packages/@romejs/core/master/project/ProjectManager.ts
@@ -28,7 +28,7 @@ import {WorkerContainer} from '../WorkerManager';
import {
DiagnosticsProcessor,
DiagnosticPointer,
- DiagnosticsError,
+ createSingleDiagnosticError,
} from '@romejs/diagnostics';
import {matchPathPatterns} from '@romejs/path-match';
import {ManifestDefinition} from '@romejs/codec-js-manifest';
@@ -747,8 +747,7 @@ export default class ProjectManager {
);
}
- throw new DiagnosticsError(`No project found for ${path.join()}`, [
- {
+ throw createSingleDiagnosticError({
...pointer,
category: 'project',
message: `Couldn't find a project`,
@@ -760,8 +759,7 @@ export default class ProjectManager {
'Run <command>rome init</command> in this folder to initialize a project',
},
],
- },
- ]);
+ });
}
// Convenience method to get the project config and pass it to the file handler class

MODIFY
packages/@romejs/core/master/testing/TestRunner.ts
packages/@romejs/core/master/testing/TestRunner.ts
@@ -309,7 +309,7 @@ export default class TestRunner {
const callFrames = params
.get('callFrames')
.asArray()
- .slice(0, 10);
+ .slice(0, 20);
for (const callFrame of callFrames) {
const loc = callFrame.get('location');
@@ -319,6 +319,8 @@ export default class TestRunner {
loc.get('columnNumber').asZeroIndexedNumber(),
);
+ console.log(callFrame.asUnknown());
+
const name = callFrame
.get('scopeChain')
.asArray()[0]

MODIFY
packages/@romejs/core/test-worker/TestWorkerRunner.ts
packages/@romejs/core/test-worker/TestWorkerRunner.ts
@@ -12,6 +12,7 @@ import {
DiagnosticsError,
getDiagnosticsFromError,
INTERNAL_ERROR_LOG_ADVICE,
+ createSingleDiagnosticError,
} from '@romejs/diagnostics';
import {TestCallback, TestOptions} from '@romejs/test';
import {
@@ -97,14 +98,12 @@ export default class TestWorkerRunner {
if (res.syntaxError !== undefined) {
const message = `A bundle was generated that contained a syntax error: ${res.syntaxError.message}`;
- throw new DiagnosticsError(message, [
- {
+ throw createSingleDiagnosticError({
...res.syntaxError,
message,
filename: this.file.uid,
advice: [INTERNAL_ERROR_LOG_ADVICE],
- },
- ]);
+ });
}
}

MODIFY
packages/@romejs/diagnostics/errors.ts
packages/@romejs/diagnostics/errors.ts
import {PartialDiagnostics} from '@romejs/diagnostics';
import {escapeMarkup} from '@romejs/string-markup';
import {stripAnsi} from '@romejs/string-ansi';
+import {printDiagnosticsToString} from '@romejs/cli-diagnostics';
+import {PartialDiagnostic} from './types';
export class DiagnosticsError extends Error {
constructor(message: string, diagnostics: PartialDiagnostics) {
@@ -16,11 +18,11 @@ export class DiagnosticsError extends Error {
}
message += '\n';
- /*message += stripAnsi(
+ message += stripAnsi(
printDiagnosticsToString(diagnostics, {
origins: [],
}),
- );*/
+ );
message += stripAnsi(
diagnostics.map(diag => `- ${diag.message}`).join('\n'),
);
@@ -28,20 +30,17 @@ export class DiagnosticsError extends Error {
super(escapeMarkup(message));
this.diagnostics = diagnostics;
this.name = 'DiagnosticsError';
-
- // If we don't have a filename then this error wont target anywhere, so add a derived error diagnostic
- // to make it easier to track
- //if (diagnostic.filename === undefined) {
- // diagnostic = mergeDiagnostics(
- // deriveDiagnosticFromError({category: 'DiagnosticError', error: this}),
- // diagnostic,
- // );
- //}
}
diagnostics: PartialDiagnostics;
}
+export function createSingleDiagnosticError(
+ diag: PartialDiagnostic,
+): DiagnosticsError {
+ return new DiagnosticsError(diag.message, [diag]);
+}
+
export function getDiagnosticsFromError(
err: Error,
): undefined | PartialDiagnostics {

MODIFY
packages/@romejs/parser-core/index.ts
packages/@romejs/parser-core/index.ts
@@ -20,6 +20,7 @@ import {
PartialDiagnosticAdvice,
DiagnosticsError,
getDiagnosticsFromError,
+ createSingleDiagnosticError,
} from '@romejs/diagnostics';
import {
Number1,
@@ -402,8 +403,7 @@ export class ParserCore<Tokens extends TokensShape, State> {
errMessage = `${this.path}: ${errMessage} Input: ${this.input}`;
}
- throw new DiagnosticsError(errMessage, [
- {
+ throw createSingleDiagnosticError({
message,
advice: opts.advice,
category: this.parserName,
@@ -412,8 +412,7 @@ export class ParserCore<Tokens extends TokensShape, State> {
start,
end,
filename: this.filename,
- },
- ]);
+ });
}
//# Token utility methods

Throw diagnostic when an argument doesn't match any files, add helper to throw a single diagnostic