Skip to content

Commit

Permalink
fix: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVolland committed Sep 16, 2024
1 parent a97e135 commit 061833d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on-push-main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Push to Master
name: Test Push to main

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ For a file leave this empty to write to `stdout`. [string]
`sld` or `se` for SLD - the parser will read the version from the file,
and `qgis` (`qml`) for QGIS QML files. If not given, it will be guessed from the extension of the input file.
Mandatory if the the target is a directory.
* `-t` / `--target` Target parser, either `mapbox` (`maplibre`), `ol`, `sld` (for SLD 1.0), `se` (for SLD 1.1),
* `-t` / `--target` Target parser, either `mapbox` (`maplibre`), `sld` (for SLD 1.0), `se` (for SLD 1.1),
and `qgis` (`qml`) for QGIS QML files. If not given, it will be guessed from
the extension of the output file. Mapfiles are not currently supported as target.
Mandatory if the the target is a directory.
Expand Down
13 changes: 3 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,6 @@ async function writeFile(
console.log(writeUnsupportedProperties);
}
output = typeof writeOutput === 'object' ? JSON.stringify(writeOutput, undefined, 2) : writeOutput;
if (targetParser instanceof OpenLayersParser) {
output = JSON.stringify(readOutput, undefined, 2);
if (!output) {
throw new Error('OpenLayers style could not be converted to JSON.');
}
}
} else {
output = JSON.stringify(readOutput, undefined, 2);
}
Expand Down Expand Up @@ -268,7 +262,7 @@ async function main() {
// Check source path arg.
if (!sourcePath) {
indicator.fail('No input file or folder specified.');
return;
return Promise.reject('No input file or folder specified.');
}

// Check source exists, is a dir or a file ?
Expand All @@ -280,12 +274,11 @@ async function main() {
// Try to define type of target (file or dir).
// Assume the target is the same as the source
let targetIsFile = sourceIsFile;
const outputExists = existsSync(outputPath);

// Dir to file is not possible
if (!sourceIsFile && targetIsFile) {
indicator.fail('The source is a directory, so the target must be directory, too.');
return;
return Promise.reject('The source is a directory, so the target must be directory, too.');
}

// Get source and target parser.
Expand All @@ -294,7 +287,7 @@ async function main() {
const targetParser = targetFormat && getParserFromFormat(targetFormat) || getParserFromFilename(outputPath);
if (!sourceParser) {
indicator.fail('No sourceparser was specified.');
return;
return Promise.reject('No sourceparser was specified.');
}
if (!targetParser) {
indicator.info('No targetparser was specified. Output will be a GeoStyler object.');
Expand Down

0 comments on commit 061833d

Please sign in to comment.