Skip to content

Commit b9d67e8

Browse files
alxndrsnspwoodcock
authored andcommitted
run-migrations: include details from Postgres errors (getodk#1415)
Noticed while working on getodk#1363. Currently, when a postgres error has additional details, `run-migrations.js` will swallow these details. # Example ## migration ```js module.exports = { down: () => {}, up: db => db.raw(` INSERT INTO config (key) VALUES('a'); INSERT INTO config (key) VALUES('a'); `), } ``` ## logging - previous `master` ``` Error: INSERT INTO config (key) VALUES('a'); INSERT INTO config (key) VALUES('a') - duplicate key value violates unique constraint "config_pkey" ``` ## logging - this commit ``` Error: INSERT INTO config (key) VALUES('a'); INSERT INTO config (key) VALUES('a') - duplicate key value violates unique constraint "config_pkey" (Key (key)=(a) already exists.) ```
1 parent cdf8e15 commit b9d67e8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/bin/run-migrations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const { withKnex, migrate } = require('../model/knex-migrator');
1313
try {
1414
await withKnex(require('config').get('default.database'))(migrate);
1515
} catch (err) {
16-
console.error('Error:', err.message);
16+
if (err.detail) console.error('Error:', err.message, `(${err.detail})`);
17+
else console.error('Error:', err.message); // eslint-disable-line no-multi-spaces
1718
process.exit(1);
1819
}
1920
})();

0 commit comments

Comments
 (0)