@@ -75,7 +75,7 @@ async function execPgDump({
75
75
} : {
76
76
pg : PGlite
77
77
args : string [ ]
78
- } ) : Promise < [ number , Uint8Array [ ] ] > {
78
+ } ) : Promise < [ number , Uint8Array [ ] , string ] > {
79
79
const bin = new URL ( './pg_dump.wasm' , import . meta. url )
80
80
const acc : Uint8Array [ ] = [ ]
81
81
const FS = emscriptenFsToWasiFS ( pg . Module . FS , acc )
@@ -89,10 +89,14 @@ async function execPgDump({
89
89
} )
90
90
91
91
wasi . stdout = ( _buffer ) => {
92
- // console.log('stdout', buffer )
92
+ // console.log('stdout', _buffer )
93
93
}
94
+ const textDecoder = new TextDecoder ( )
95
+ let errorMessage = ''
96
+
94
97
wasi . stderr = ( _buffer ) => {
95
- // console.error('stderr', buffer)
98
+ const text = textDecoder . decode ( _buffer )
99
+ if ( text ) errorMessage += text
96
100
}
97
101
wasi . sched_yield = ( ) => {
98
102
const pgIn = '/tmp/pglite/base/.s.PGSQL.5432.in'
@@ -144,7 +148,7 @@ async function execPgDump({
144
148
await pg . runExclusive ( async ( ) => {
145
149
exitCode = wasi . start ( app . instance . exports )
146
150
} )
147
- return [ exitCode ! , acc ]
151
+ return [ exitCode ! , acc , errorMessage ]
148
152
}
149
153
150
154
interface PgDumpOptions {
@@ -173,13 +177,15 @@ export async function pgDump({
173
177
'postgres' ,
174
178
]
175
179
176
- const [ exitCode , acc ] = await execPgDump ( {
180
+ const [ exitCode , acc , errorMessage ] = await execPgDump ( {
177
181
pg,
178
182
args : [ ...( args ?? [ ] ) , ...baseArgs ] ,
179
183
} )
180
184
181
185
if ( exitCode !== 0 ) {
182
- throw new Error ( `pg_dump failed with exit code ${ exitCode } ` )
186
+ throw new Error (
187
+ `pg_dump failed with exit code ${ exitCode } . \nError message: ${ errorMessage } ` ,
188
+ )
183
189
}
184
190
185
191
const file = new File ( acc , fileName , {
0 commit comments