Skip to content

Commit

Permalink
fix(rosetta): crashes on outdated tablet files in a package (#3119)
Browse files Browse the repository at this point in the history
A package may accidentally (or on purpose) contain a `.jsii.tabl.json`
file, containing pretranslated examples.

When an assembly is added for snippet discovery, this tablet will
be loaded implicitly to save live conversion time.

However, if the tablet file is old, or not even a tablet file, this
will stop rosetta with an error. Catch that error and continue
anyway.

Fixes an issue in Construct Hub.



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
rix0rrr authored Nov 4, 2021
1 parent 4e28855 commit 80ff0dc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/jsii-rosetta/lib/rosetta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isError } from 'util';

import { allTypeScriptSnippets } from './jsii/assemblies';
import { TargetLanguage } from './languages';
import * as logging from './logging';
import { transformMarkdown } from './markdown/markdown';
import { MarkdownRenderer } from './markdown/markdown-renderer';
import { ReplaceTypeScriptTransform } from './markdown/replace-typescript-transform';
Expand Down Expand Up @@ -109,17 +110,23 @@ export class Rosetta {
* Add an assembly
*
* If a default tablet file is found in the assembly's directory, it will be
* loaded.
* loaded (and assumed to contain a complete list of translated snippets for
* this assembly already).
*
* Otherwise, if live conversion is enabled, the snippets in the assembly
* become available for live translation later. This is necessary because we probably
* need to fixture snippets for successful compilation, and the information
* pacmak sends our way later on is not going to be enough to do that.
*/
public async addAssembly(assembly: spec.Assembly, assemblyDir: string) {
if (await fs.pathExists(path.join(assemblyDir, DEFAULT_TABLET_NAME))) {
await this.loadTabletFromFile(path.join(assemblyDir, DEFAULT_TABLET_NAME));
return;
const defaultTablet = path.join(assemblyDir, DEFAULT_TABLET_NAME);
if (await fs.pathExists(defaultTablet)) {
try {
await this.loadTabletFromFile(defaultTablet);
return;
} catch (e) {
logging.warn(`Error loading ${defaultTablet}: ${e.message}. Skipped.`);
}
}

if (this.options.liveConversion) {
Expand Down

0 comments on commit 80ff0dc

Please sign in to comment.