Skip to content

Commit

Permalink
fix: incorrect error thrown for transliteration failures (#1542)
Browse files Browse the repository at this point in the history
This leads to downstream tools reacting incorrectly. While both errors "Unsupported language" &  "Transliteration error"   indicate a fix is required by the assembly producer, the reaction might be handled differently by the upstream tool. For example a "Transliteration error" should indicate to stop processing all other submodules.
  • Loading branch information
mrgrain authored Aug 27, 2024
1 parent cd5597a commit 7ed32c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/docgen/view/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TargetLanguage, transliterateAssembly, UnknownSnippetMode } from 'jsii-
import { Npm } from './_npm';
import { ApiReference } from './api-reference';
import { Readme } from './readme';
import { CorruptedAssemblyError, LanguageNotSupportedError } from '../..';
import { CorruptedAssemblyError, LanguageNotSupportedError, TransliterationError } from '../..';
import { Json } from '../render/json';
import { MarkdownDocument } from '../render/markdown-doc';
import { MarkdownFormattingOptions, MarkdownRenderer } from '../render/markdown-render';
Expand Down Expand Up @@ -427,7 +427,7 @@ export class Documentation {
await transliterateAssembly([packageDir], [language],
{ loose: options.loose, unknownSnippets: UnknownSnippetMode.FAIL, outdir: workdir });
} catch (e: any) {
throw new LanguageNotSupportedError(`Laguage ${language} is not supported for package ${this.assemblyFqn} (cause: ${e.message})`);
throw new TransliterationError(`Could not transliterate snippets in '${this.assemblyFqn}' to ${language}: ${e.message}`);
}
dotJsii = path.join(workdir, `${SPEC_FILE_NAME}.${language}`);
}
Expand Down
5 changes: 5 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export class CorruptedAssemblyError extends DocGenError {}
*/
export class LanguageNotSupportedError extends DocGenError {};

/**
* Raised when snippet transliteration into a target language failed.
*/
export class TransliterationError extends DocGenError {};

/**
* The error raised when `npm` commands fail with an "opaque" exit code,
* attempting to obtain more information from the commands output.
Expand Down
8 changes: 4 additions & 4 deletions test/docgen/view/documentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as child from 'child_process';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs-extra';
import { Language, Documentation, UnInstallablePackageError, CorruptedAssemblyError, LanguageNotSupportedError } from '../../../src';
import { Language, Documentation, UnInstallablePackageError, CorruptedAssemblyError, LanguageNotSupportedError, TransliterationError } from '../../../src';
import { extractPackageName } from '../../../src/docgen/view/documentation';
import { Assemblies } from '../assemblies';

Expand Down Expand Up @@ -269,10 +269,10 @@ test('throws unsupported language with invalid config', async () => {
await expect(docs.toJson({ language: Language.GO })).rejects.toThrowError(LanguageNotSupportedError);
});

test('throws unsupported language when tablet was generated before rosetta supported go', async () => {
test('throws transliteration error when tablet was generated before rosetta supported go', async () => {
const docs = await Documentation.forPackage('[email protected]', { verbose: false });
await expect(docs.toMarkdown({ language: Language.GO })).rejects.toThrowError(LanguageNotSupportedError);
await expect(docs.toJson({ language: Language.GO })).rejects.toThrowError(LanguageNotSupportedError);
await expect(docs.toMarkdown({ language: Language.GO })).rejects.toThrowError(TransliterationError);
await expect(docs.toJson({ language: Language.GO })).rejects.toThrowError(TransliterationError);
});

test('does not throw if unrelated assembly is corrupted', async () => {
Expand Down

0 comments on commit 7ed32c3

Please sign in to comment.