Skip to content

Commit

Permalink
fix: user-friendly error message "Error: buffer is not ico"
Browse files Browse the repository at this point in the history
Closes #349
  • Loading branch information
develar committed May 7, 2016
1 parent 16d3805 commit 7ac6ca2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/winPackagerTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
"should": "^8.3.1",
"ts-babel": "^0.8.6",
"tsconfig-glob": "^0.4.3",
"tslint": "next",
"typescript": "1.9.0-dev.20160505",
"tslint": "^3.9.0-dev.0",
"typescript": "1.9.0-dev.20160507",
"whitespace": "^2.0.0"
},
"babel": {
Expand Down
6 changes: 5 additions & 1 deletion src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,18 @@ async function checkIcon(file: string): Promise<void> {
await close(fd)
}

if (!isIco(buffer)) {
throw new Error(`Windows icon is not valid ico file, please fix "${file}"`)
}

const sizes = parseIco(buffer)
for (let size of sizes) {
if (size!.w >= 256 && size!.h >= 256) {
return
}
}

throw new Error("Windows icon image size must be at least 256x256")
throw new Error(`Windows icon size must be at least 256x256, please fix "${file}"`)
}

interface Size {
Expand Down
8 changes: 6 additions & 2 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Platform } from "out"
import test from "./helpers/avaEx"
import { assertPack, platform, modifyPackageJson } from "./helpers/packTester"
import { move } from "fs-extra-p"
import { move, outputFile } from "fs-extra-p"
import * as path from "path"
import { WinPackager, computeDistOut } from "out/winPackager"
import { BuildInfo } from "out/platformPackager"
Expand Down Expand Up @@ -69,7 +69,11 @@ test("detect install-spinner", () => {

test.ifNotCiOsx("icon < 256", (t: any) => t.throws(assertPack("test-app-one", platform(Platform.WINDOWS), {
tempDirCreated: projectDir => move(path.join(projectDir, "build", "incorrect.ico"), path.join(projectDir, "build", "icon.ico"), {clobber: true})
}), /Windows icon image size must be at least 256x256/))
}), /Windows icon size must be at least 256x256, please fix ".+/))

test.ifNotCiOsx("icon not an image", (t: any) => t.throws(assertPack("test-app-one", platform(Platform.WINDOWS), {
tempDirCreated: projectDir => outputFile(path.join(projectDir, "build", "icon.ico"), "foo")
}), /Windows icon is not valid ico file, please fix ".+/))

class CheckingWinPackager extends WinPackager {
effectiveDistOptions: any
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@
"no-invalid-this": true,
"no-reference": true,
"semicolon": "never",
"prefer-const": "true"
"prefer-const": "true",
"one-variable-per-declaration": "true"
}

0 comments on commit 7ac6ca2

Please sign in to comment.