Skip to content

Commit

Permalink
Introduced a new debug flag for quick handling of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofVDB1 committed Nov 14, 2024
1 parent 8893587 commit 5243203
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 36 deletions.
65 changes: 39 additions & 26 deletions packages/oslo-converter-uml-ea/lib/EaUmlConversionServiceRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,57 @@ import { container } from './config/DependencyInjectionConfig';
import type { EaUmlConverterConfiguration } from './config/EaUmlConverterConfiguration';
import type { EaUmlConversionService } from './EaUmlConversionService';

export class EaUmlConversionServiceRunner extends AppRunner<EaUmlConversionService, EaUmlConverterConfiguration> {
export class EaUmlConversionServiceRunner extends AppRunner<
EaUmlConversionService,
EaUmlConverterConfiguration
> {
public async runCli(argv: CliArgv): Promise<void> {
const yargv = yargs(argv.slice(2))
.usage('node ./bin/runner.js [args]')
.option('umlFile', { describe: 'URL or local path to an EAP file.' })
.option('diagramName', { describe: 'Name of the diagram within the EAP file.' })
.option('outputFile',
{
describe: 'Name of the output file (default: console).',
})
.option('versionId', { describe: 'Relative URI used to identify this document.' })
.option('outputFormat',
{
describe: 'RDF content-type in which the output must be written or to the console.',
choices: ['application/ld+json', 'application/trig'],
default: 'application/ld+json',
})
.option('publicationEnvironment',
{
describe: 'The base URI of environment where the document will be published',
})
.option('silent',
{
describe: 'All logs are suppressed',
default: false,
boolean: true,
})
.option('diagramName', {
describe: 'Name of the diagram within the EAP file.',
})
.option('outputFile', {
describe: 'Name of the output file (default: console).',
})
.option('versionId', {
describe: 'Relative URI used to identify this document.',
})
.option('outputFormat', {
describe:
'RDF content-type in which the output must be written or to the console.',
choices: ['application/ld+json', 'application/trig'],
default: 'application/ld+json',
})
.option('publicationEnvironment', {
describe:
'The base URI of environment where the document will be published',
})
.option('silent', {
describe: 'All logs are suppressed',
default: false,
boolean: true,
})
.option('logLevel', {
describe: 'Log only if level is less than or equal to this level',
default: 'info',
choices: LOG_LEVELS,
})
.demandOption(['umlFile', 'diagramName', 'versionId', 'publicationEnvironment'],
'Please provide the necessary arguments to work with this tool.')
.option('debug', {
describe:
'A flag to enable debug mode which is more resilient to errors',
default: false,
boolean: true,
})
.demandOption(
['umlFile', 'diagramName', 'versionId', 'publicationEnvironment'],
'Please provide the necessary arguments to work with this tool.',
)
.help('h')
.alias('h', 'help');

const params = await yargv.parse();
this.startApp(params, container).catch(error => console.error(error));
this.startApp(params, container).catch((error) => console.error(error));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class EaUmlConverterConfiguration implements IConfiguration {
* The base URI of the environment where the document will be published
*/
private _publicationEnvironment: string | undefined;
/**
* A boolean to enable debug mode which is more resilient to errors
*/
private _debug: boolean | undefined;

public async createFromCli(params: YargsParams): Promise<void> {
this._umlFile = <string>params.umlFile;
Expand All @@ -40,6 +44,7 @@ export class EaUmlConverterConfiguration implements IConfiguration {
this._versionId = <string>params.versionId;
this._outputFormat = <string>params.outputFormat;
this._publicationEnvironment = <string>params.publicationEnvironment;
this._debug = <boolean>params.debug;
}

public get umlFile(): string {
Expand All @@ -51,36 +56,50 @@ export class EaUmlConverterConfiguration implements IConfiguration {

public get diagramName(): string {
if (!this._diagramName) {
throw new Error(`Trying to access property "diagramName" before it was set.`);
throw new Error(
`Trying to access property "diagramName" before it was set.`
);
}
return this._diagramName;
}

public get outputFile(): string {
if (!this._outputFile) {
throw new Error(`Trying to access property "outputFile" before it was set.`);
throw new Error(
`Trying to access property "outputFile" before it was set.`
);
}
return this._outputFile;
}

public get versionId(): string {
if (!this._versionId) {
throw new Error(`Trying to access property "versionId" before it was set.`);
throw new Error(
`Trying to access property "versionId" before it was set.`
);
}
return this._versionId;
}

public get outputFormat(): string {
if (!this._outputFormat) {
throw new Error(`Trying to access property "outputFormat" before it was set.`);
throw new Error(
`Trying to access property "outputFormat" before it was set.`
);
}
return this._outputFormat;
}

public get publicationEnvironment(): string {
if (!this._publicationEnvironment) {
throw new Error(`Trying to access property "publicationEnvironment" before it was set.`);
throw new Error(
`Trying to access property "publicationEnvironment" before it was set.`
);
}
return this._publicationEnvironment;
}

public get debug(): boolean {
return !!this._debug;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ export class AttributeConverterHandler extends ConverterHandler<EaAttribute> {
}
}

if (!rangeURI) {
throw new Error(
`[AttributeConverterHandler]: Unable to get the URI for the range of attribute (${object.path}).`
);
// https://vlaamseoverheid.atlassian.net/browse/SDTT-344
// Needed a way to log errors without throwing them so that the conversion process can continue
if (this.handleRangeError(object, rangeURI)) {
return [];
}

quads.push(
Expand Down Expand Up @@ -362,6 +362,22 @@ export class AttributeConverterHandler extends ConverterHandler<EaAttribute> {
return quads;
}

private handleRangeError(
object: EaAttribute,
rangeURI: string | null
): boolean {
if (!rangeURI) {
const error: string = `[AttributeConverterHandler]: Unable to determine the range for attribute (${object.path}).`;
if (this.config.debug) {
this.logger.error(error);
return true;
} else {
throw new Error(error);
}
}
return false;
}

private getDatatypeQuads(
rangeInternalId: RDF.NamedNode,
rangeAssignedURI: RDF.NamedNode,
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-converter-uml-ea/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oslo-flanders/ea-converter",
"version": "0.0.34-alpha.0",
"version": "0.0.35-alpha.0",
"description": "Transform an Enterprise Architect UML diagram to RDF",
"author": "Digitaal Vlaanderen <https://data.vlaanderen.be/id/organisatie/OVO002949>",
"homepage": "https://github.com/informatievlaanderen/OSLO-UML-Transformer/tree/main/packages/oslo-converter-uml-ea#readme",
Expand Down

0 comments on commit 5243203

Please sign in to comment.