1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-03 04:29:33 +00:00

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) { } else if (oReq.status == 404) {
success(null); success(null);
} else { } else {
throw "Error " + oReq.status + " loading " + url; throw Error("Error " + oReq.status + " loading " + url);
} }
} }
oReq.send(null); oReq.send(null);

View File

@ -442,7 +442,7 @@ export class TextDataNode extends CodeProjectDataNode {
} }
updateLeft() { updateLeft() {
if (this.right.words.length != this.words.length) 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; this.words = this.right.words;
// TODO: reload editors? // TODO: reload editors?
var datastr = this.text.substring(this.start, this.end); 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 row=0; row<this.rows; row++) {
for (var col=0; col<this.cols; col++) { for (var col=0; col<this.cols; col++) {
var name = this.words[this.baseofs + a]; 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]; 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); attraddr = (a & 0x2c00) | 0x3c0 | (a & 0x0C00) | ((a >> 4) & 0x38) | ((a >> 2) & 0x07);
var attr = this.words[attraddr]; var attr = this.words[attraddr];
var tag = name ^ (attr<<9) ^ 0x80000000; var tag = name ^ (attr<<9) ^ 0x80000000;

View File

@ -245,7 +245,7 @@ export class CodeProject {
} }
sendBuild() { 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); var maindata = this.getFile(this.mainpath);
// if binary blob, just return it as ROM // if binary blob, just return it as ROM
if (maindata instanceof Uint8Array) { if (maindata instanceof Uint8Array) {

View File

@ -156,7 +156,7 @@ export class GithubService {
return sess.repo.git.trees(subtree.sha).fetch(); 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; return tree;
}) })
@ -207,7 +207,7 @@ export class GithubService {
if (m) { if (m) {
console.log("platform id: '" + m[1] + "'"); console.log("platform id: '" + m[1] + "'");
if (sess.platform_id && !sess.platform_id.startsWith(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]; sess.platform_id = m[1];
} }
// bind to repository // bind to repository
@ -295,7 +295,7 @@ export class GithubService {
return this.getGithubHEADTree(ghurl).then( (session) => { return this.getGithubHEADTree(ghurl).then( (session) => {
sess = session; sess = session;
if (sess.subtreepath) { 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) => { return Promise.all(files.map( (file) => {
if (typeof file.data === 'string') { if (typeof file.data === 'string') {

View File

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

View File

@ -122,7 +122,7 @@ var AtariVectorPlatform = function(mainElement) {
this.loadROM = function(title, data) { this.loadROM = function(title, data) {
if(data.length != 0x2000) { if(data.length != 0x2000) {
throw "ROM length must be == 0x2000"; throw Error("ROM length must be == 0x2000");
} }
rom = data.slice(0,0x1800); rom = data.slice(0,0x1800);
vecrom = data.slice(0x1800,0x2000); 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 var strfn = byteArrayToString(barr); // convert to string
// parse hex/binary file // parse hex/binary file
var strdata = current_project.getFile(strfn) as string; 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)); var data = strdata.split('\n').filter(s => s !== '').map(s => parseInt(s, ishex ? 16 : 2));
console.log('$readmem', ishex, strfn, data.length); console.log('$readmem', ishex, strfn, data.length);
// copy into destination array // copy into destination array
if (memp === null) throw "No destination array to $readmem " + strfn; if (memp === null) throw Error("No destination array to $readmem " + strfn);
if (memp.length < data.length) throw "Destination array too small to $readmem " + strfn; if (memp.length < data.length) throw Error("Destination array too small to $readmem " + strfn);
for (i=0; i<data.length; i++) for (i=0; i<data.length; i++)
memp[i] = data[i]; memp[i] = data[i];
} }

View File

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

View File

@ -64,7 +64,7 @@ describe('Store', function() {
var store = mstore.createNewPersistentStore('_FOO', function(store) { var store = mstore.createNewPersistentStore('_FOO', function(store) {
var gh = newGH(store, '_FOO'); var gh = newGH(store, '_FOO');
gh.importAndPull('https://github.com/pzpinfo/testrepo1557326056720').catch( (e) => { gh.importAndPull('https://github.com/pzpinfo/testrepo1557326056720').catch( (e) => {
assert.ok(e.startsWith('Platform mismatch')); assert.ok(e.message.startsWith('Platform mismatch'));
done(); done();
}); });
}); });
@ -145,7 +145,7 @@ describe('Store', function() {
gh.commit('https://github.com/brovador/NESnake/tree/master/src', 'test commit', files) gh.commit('https://github.com/brovador/NESnake/tree/master/src', 'test commit', files)
.catch( (e) => { .catch( (e) => {
console.log(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(); done();
}); });
/*.then( (sess) => { /*.then( (sess) => {