Skip to content

Commit

Permalink
patch: don't crash on watch+compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 5, 2022
1 parent 619feca commit c360034
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,20 @@ async function getHost(options: BuildOptions & CmdOptions) {
return jacsHost
}

export class CompilationError extends Error {
constructor(message: string) {
super(message)
this.name = "CompilationError"
}
}

async function compileBuf(buf: Buffer, options: BuildOptions) {
const host = await getHost(options)
const res = compile(buf.toString("utf8"), {
host,
isLibrary: options.library,
})
if (!res.success) throw new Error("compilation failed")
if (!res.success) throw new CompilationError("compilation failed")
return res.binary
}

Expand Down Expand Up @@ -122,6 +129,7 @@ async function buildWatch(file: string, options: BuildOptions) {
}

async function buildOnce(file: string, options: BuildOptions & CmdOptions) {
const { watch } = options
try {
if (!pathExistsSync(file))
throw new Error(`source file ${file} not found`)
Expand All @@ -132,6 +140,7 @@ async function buildOnce(file: string, options: BuildOptions & CmdOptions) {
debug(e.message)
debug(e.stack)
}
if (e instanceof CompilationError && watch) return
throw e
}
}

0 comments on commit c360034

Please sign in to comment.