Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 21, 2024
1 parent e0cf4fa commit 4e5253e
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/migrate/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ export function update_svelte_file(file_path, transform_script_code, transform_s
}
);
fs.writeFileSync(file_path, transform_svelte_code(updated, file_path), 'utf-8');
} catch (e) {
console.error(`Error updating ${file_path}:`, e);
} catch (err) {
// TODO: change to import('svelte/compiler').Warning after upgrading to Svelte 5
const e = (/** @type {any} */ (err));
console.warn(buildExtendedLogMessage(e), e.frame);
console.info(e.stack);
}
}

Expand All @@ -327,11 +330,34 @@ export function update_js_file(file_path, transform_code) {
const content = fs.readFileSync(file_path, 'utf-8');
const updated = transform_code(content, file_path.endsWith('.ts'), file_path);
fs.writeFileSync(file_path, updated, 'utf-8');
} catch (e) {
console.error(`Error updating ${file_path}:`, e);
} catch (err) {
// TODO: change to import('svelte/compiler').Warning after upgrading to Svelte 5
const e = (/** @type {any} */ (err));
console.warn(buildExtendedLogMessage(e), e.frame);
console.info(e.stack);
}
}

/**
* @param {any} w
*/
export function buildExtendedLogMessage(w) {
const parts = [];
if (w.filename) {
parts.push(w.filename);
}
if (w.start) {
parts.push(':', w.start.line, ':', w.start.column);
}
if (w.message) {
if (parts.length > 0) {
parts.push(' ');
}
parts.push(w.message);
}
return parts.join('');
}

/**
* Updates the tsconfig/jsconfig.json file with the provided function.
* @param {(content: string) => string} update_tsconfig_content
Expand Down

0 comments on commit 4e5253e

Please sign in to comment.