use throw Error() when possible

This commit is contained in:
Steven Hugg 2019-11-13 14:45:18 -06:00
parent e97123bfae
commit f7ade09225
9 changed files with 22 additions and 22 deletions

View File

@ -461,7 +461,7 @@ export function getWithBinary(url:string, success:(text:string|Uint8Array)=>void
} else if (oReq.status == 404) {
success(null);
} else {
throw "Error " + oReq.status + " loading " + url;
throw Error("Error " + oReq.status + " loading " + url);
}
}
oReq.send(null);

View File

@ -442,7 +442,7 @@ export class TextDataNode extends CodeProjectDataNode {
}
updateLeft() {
if (this.right.words.length != this.words.length)
throw "Expected " + this.right.words.length + " bytes; image has " + this.words.length;
throw Error("Expected " + this.right.words.length + " bytes; image has " + this.words.length);
this.words = this.right.words;
// TODO: reload editors?
var datastr = this.text.substring(this.start, this.end);
@ -715,9 +715,9 @@ export class NESNametableConverter extends Compositor {
for (var row=0; row<this.rows; row++) {
for (var col=0; col<this.cols; col++) {
var name = this.words[this.baseofs + a];
if (typeof name === 'undefined') throw "No name for address " + this.baseofs + " + " + a;
if (typeof name === 'undefined') throw Error("No name for address " + this.baseofs + " + " + a);
var t = this.tilemap[name];
if (!t) throw "No tilemap found for tile index " + name;
if (!t) throw Error("No tilemap found for tile index " + name);
attraddr = (a & 0x2c00) | 0x3c0 | (a & 0x0C00) | ((a >> 4) & 0x38) | ((a >> 2) & 0x07);
var attr = this.words[attraddr];
var tag = name ^ (attr<<9) ^ 0x80000000;

View File

@ -245,7 +245,7 @@ export class CodeProject {
}
sendBuild() {
if (!this.mainpath) throw "need to call setMainFile first";
if (!this.mainpath) throw Error("need to call setMainFile first");
var maindata = this.getFile(this.mainpath);
// if binary blob, just return it as ROM
if (maindata instanceof Uint8Array) {

View File

@ -156,7 +156,7 @@ export class GithubService {
return sess.repo.git.trees(subtree.sha).fetch();
}
}
throw "Cannot find subtree '" + sess.subtreepath + "' in tree " + tree.sha;
throw Error("Cannot find subtree '" + sess.subtreepath + "' in tree " + tree.sha);
}
return tree;
})
@ -207,7 +207,7 @@ export class GithubService {
if (m) {
console.log("platform id: '" + m[1] + "'");
if (sess.platform_id && !sess.platform_id.startsWith(m[1]))
throw "Platform mismatch: Repository is " + m[1] + ", you have " + this.project.platform_id + " selected.";
throw Error("Platform mismatch: Repository is " + m[1] + ", you have " + this.project.platform_id + " selected.");
sess.platform_id = m[1];
}
// bind to repository
@ -295,7 +295,7 @@ export class GithubService {
return this.getGithubHEADTree(ghurl).then( (session) => {
sess = session;
if (sess.subtreepath) {
throw "Sorry, right now you can only commit files to the root directory of a repository.";
throw Error("Sorry, right now you can only commit files to the root directory of a repository.");
}
return Promise.all(files.map( (file) => {
if (typeof file.data === 'string') {

View File

@ -191,7 +191,7 @@ export class SMS extends SG1000 {
this.romPageMask = (data.length >> 14) - 1; // div $4000
break;
default:
throw "Unknown rom size: $" + hex(data.length);
throw Error("Unknown rom size: $" + hex(data.length));
}
}
//console.log("romPageMask: " + hex(this.romPageMask));

View File

@ -122,7 +122,7 @@ var AtariVectorPlatform = function(mainElement) {
this.loadROM = function(title, data) {
if(data.length != 0x2000) {
throw "ROM length must be == 0x2000";
throw Error("ROM length must be == 0x2000");
}
rom = data.slice(0,0x1800);
vecrom = data.slice(0x1800,0x2000);

View File

@ -140,12 +140,12 @@ export function VL_READMEM_W(ishex,width,depth,array_lsb,fnwords,filename,memp,s
var strfn = byteArrayToString(barr); // convert to string
// parse hex/binary file
var strdata = current_project.getFile(strfn) as string;
if (strdata == null) throw "Could not $readmem '" + strfn + "'";
if (strdata == null) throw Error("Could not $readmem '" + strfn + "'");
var data = strdata.split('\n').filter(s => s !== '').map(s => parseInt(s, ishex ? 16 : 2));
console.log('$readmem', ishex, strfn, data.length);
// copy into destination array
if (memp === null) throw "No destination array to $readmem " + strfn;
if (memp.length < data.length) throw "Destination array too small to $readmem " + strfn;
if (memp === null) throw Error("No destination array to $readmem " + strfn);
if (memp.length < data.length) throw Error("Destination array too small to $readmem " + strfn);
for (i=0; i<data.length; i++)
memp[i] = data[i];
}

View File

@ -353,7 +353,7 @@ function gatherFiles(step:BuildStep, options?:BuildOptions) {
}
else if (step.code) {
var path = step.path ? step.path : options.mainFilePath; // TODO: what if options null
if (!path) throw "need path or mainFilePath";
if (!path) throw Error("need path or mainFilePath");
var code = step.code;
var entry = putWorkFile(path, code);
step.path = path;
@ -378,7 +378,7 @@ function gatherFiles(step:BuildStep, options?:BuildOptions) {
function populateFiles(step:BuildStep, fs, options?:BuildOptions) {
gatherFiles(step, options);
if (!step.files) throw "call gatherFiles() first";
if (!step.files) throw Error("call gatherFiles() first");
for (var i=0; i<step.files.length; i++) {
var path = step.files[i];
populateEntry(fs, path, workfs[path], options);
@ -413,7 +413,7 @@ function populateExtraFiles(step:BuildStep, fs, extrafiles) {
}
function staleFiles(step:BuildStep, targets:string[]) {
if (!step.maxts) throw "call populateFiles() first";
if (!step.maxts) throw Error("call populateFiles() first");
// see if any target files are more recent than inputs
for (var i=0; i<targets.length; i++) {
var entry = workfs[targets[i]];
@ -425,7 +425,7 @@ function staleFiles(step:BuildStep, targets:string[]) {
}
function anyTargetChanged(step:BuildStep, targets:string[]) {
if (!step.maxts) throw "call populateFiles() first";
if (!step.maxts) throw Error("call populateFiles() first");
// see if any target files are more recent than inputs
for (var i=0; i<targets.length; i++) {
var entry = workfs[targets[i]];
@ -509,7 +509,7 @@ function setupFS(FS, name:string) {
var WORKERFS = FS.filesystems['WORKERFS'];
if (name === '65-vector') name = '65-sim6502'; // TODO
if (name === '65-atari7800') name = '65-sim6502'; // TODO
if (!fsMeta[name]) throw "No filesystem for '" + name + "'";
if (!fsMeta[name]) throw Error("No filesystem for '" + name + "'");
FS.mkdir('/share');
FS.mount(WORKERFS, {
packages: [{ metadata: fsMeta[name], blob: fsBlob[name] }]
@ -1491,7 +1491,7 @@ function compileJSASM(asmcode:string, platform, options, is_inline) {
var includes = [];
asm.loadJSON = (filename:string) => {
var jsontext = getWorkFileAsString(filename);
if (!jsontext) throw "could not load " + filename;
if (!jsontext) throw Error("could not load " + filename);
return JSON.parse(jsontext);
};
asm.loadInclude = function(filename) {
@ -2106,7 +2106,7 @@ function executeBuildSteps() {
var step = buildsteps.shift(); // get top of array
var platform = step.platform;
var toolfn = TOOLS[step.tool];
if (!toolfn) throw "no tool named " + step.tool;
if (!toolfn) throw Error("no tool named " + step.tool);
step.params = PLATFORM_PARAMS[getBasePlatform(platform)];
try {
step.result = toolfn(step);

View File

@ -64,7 +64,7 @@ describe('Store', function() {
var store = mstore.createNewPersistentStore('_FOO', function(store) {
var gh = newGH(store, '_FOO');
gh.importAndPull('https://github.com/pzpinfo/testrepo1557326056720').catch( (e) => {
assert.ok(e.startsWith('Platform mismatch'));
assert.ok(e.message.startsWith('Platform mismatch'));
done();
});
});
@ -145,7 +145,7 @@ describe('Store', function() {
gh.commit('https://github.com/brovador/NESnake/tree/master/src', 'test commit', files)
.catch( (e) => {
console.log(e);
assert.equal(e, 'Sorry, right now you can only commit files to the root directory of a repository.');
assert.equal(e.message, 'Sorry, right now you can only commit files to the root directory of a repository.');
done();
});
/*.then( (sess) => {