diff --git a/services/adapter.ts b/services/adapter.ts index 607f260..10d9bd9 100644 --- a/services/adapter.ts +++ b/services/adapter.ts @@ -34,7 +34,7 @@ export const asyncExecFile: ( ) => Promise = Bluebird.Promise.promisify(execFile); export const asyncStat: (path: string) => Promise = Bluebird.Promise.promisify(fs.stat); export const asyncUnlink: (path: string) => Promise = Bluebird.Promise.promisify(fs.unlink); -export const asyncReadFile: (path: string, options?: any) => Promise = Bluebird.Promise.promisify(fs.readFile); +export const asyncReadFile: (path: string, options?: any) => Promise = Bluebird.Promise.promisify(fs.readFile); export const asyncWriteFile: (path: string, contents: string, options?: fs.WriteFileOptions) => Promise = Bluebird.Promise.promisify( fs.writeFile, ); diff --git a/services/service.ts b/services/service.ts index 1fac3f3..dae0b9d 100644 --- a/services/service.ts +++ b/services/service.ts @@ -527,10 +527,14 @@ function runService() { // RootMyTV v1 if (await isFile(startDevmode)) { const localChecksum = await hashFile(startDevmode, 'sha256'); + // Warn and return empty string on read error + let startDevmodeContents = await asyncReadFile(startDevmode, { encoding: 'utf-8'} ) + .catch((err) => (console.warn(`reading ${startDevmode} failed: ${err.toString()}`), '')) as string; + if (localChecksum !== bundledStartupChecksum && updatableChecksums.indexOf(localChecksum) !== -1) { await copyScript(bundledStartup, startDevmode); messages.push(`${startDevmode} updated!`); - } else if (localChecksum !== bundledJumpstartChecksum && (await asyncReadFile(startDevmode)).indexOf('org.webosbrew') !== -1) { + } else if (localChecksum !== bundledJumpstartChecksum && startDevmodeContents.indexOf('org.webosbrew') !== -1) { // Show notification about mismatched startup script if contains // org.webosbrew string (which is not used on jumpstart.sh nor // official start-devmode.sh) @@ -538,9 +542,10 @@ function runService() { } } } catch (err) { + console.log(`Startup script update failed: ${err.stack}`); messages = ['Startup script update failed!', ...messages, `Error: ${err.toString()}`]; await createToast(messages.join('
'), service); - return { returnValue: false, statusText: 'Startup script update failed.', messages }; + return { returnValue: false, statusText: 'Startup script update failed.', stack: err.stack, messages }; } if (messages.length) {