Skip to content

Commit

Permalink
fix: improve err messages for song imports
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Chodur <[email protected]>
  • Loading branch information
FUSAKLA committed Apr 6, 2024
1 parent 82c9a33 commit 3d84eb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion appsscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"https://pdfmerge.w69b.com/",
"https://api.qrserver.com/",
"https://acordes.lacuerda.net/",
"https://www.songbook.fun/"
"https://www.songbook.fun/",
"https://cifraclub.com.br/",
"https://www.cifraclub.com.br/"
]
},
"docs": {}
Expand Down
12 changes: 7 additions & 5 deletions src/import/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function writeChordsToDocument(
}

function importUrl(url: string, currentDoc: boolean) {
const errPrefix = "Failed to import chords from " + url + ": ";
const supportedSites = getSupportedChordsImportSites();
let chords: chordSiteData;
let matchingSite: importSite | null = null;
Expand All @@ -109,19 +110,20 @@ function importUrl(url: string, currentDoc: boolean) {
}

if (matchingSite === null) {
throw Error("Unsupported site for import.");
throw Error(
errPrefix +
"Unsupported site, if you would like to import chords from this site, please contact the developer."
);
}

try {
chords = matchingSite.processor(url);
} catch (e) {
throw Error(
"Failed to import data from " + matchingSite.domain + ": " + e.message
);
throw Error(errPrefix + e.message);
}

if (chords === null || chords.rows.length === 0) {
throw Error("Import error: No chords found.");
throw Error(errPrefix + "No chords found.");
}

let targetDoc = DocumentApp.getActiveDocument();
Expand Down

0 comments on commit 3d84eb8

Please sign in to comment.