Skip to content

Commit

Permalink
Merge branch 'master' into enhanced-launch
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron authored Mar 1, 2024
2 parents d474400 + a5e3600 commit 1b4f73e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



## [3.11.3](https://github.com/rokucommunity/roku-deploy/compare/v3.11.2...v3.11.3) - 2024-02-29
### Fixed
- Retry the convertToSquahsfs request to mitigate the HPE_INVALID_CONSTANT error ([#145](https://github.com/rokucommunity/roku-deploy/pull/145))



## [3.11.2](https://github.com/rokucommunity/roku-deploy/compare/v3.11.1...v3.11.2) - 2023-12-20
### Changed
- Update wrong host password error message ([#134](https://github.com/rokucommunity/roku-deploy/pull/134))
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roku-deploy",
"version": "3.11.2",
"version": "3.11.3",
"description": "Package and publish a Roku application using Node.js",
"main": "dist/index.js",
"scripts": {
Expand Down
69 changes: 69 additions & 0 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,77 @@ describe('index', () => {
}
assert.fail('Should not have succeeded');
});

it('should throw with HPE_INVALID_CONSTANT and then succeed on retry', async () => {
let doPostStub = sinon.stub(rokuDeploy as any, 'doPostRequest');
doPostStub.onFirstCall().throws((params) => {
throw new ErrorWithCode();
});
doPostStub.onSecondCall().returns({ body: '..."fileType":"squashfs"...' });
try {
await rokuDeploy.convertToSquashfs(options);
} catch (e) {
assert.fail('Should not have throw');
}
});

it('should throw and not retry', async () => {
let doPostStub = sinon.stub(rokuDeploy as any, 'doPostRequest');
doPostStub.onFirstCall().throws((params) => {
throw new ErrorWithCode('Something else');
});
try {
await rokuDeploy.convertToSquashfs(options);
} catch (e) {
expect(e).to.be.instanceof(ErrorWithCode);
expect(e['code']).to.be.eql('Something else');
return;
}
assert.fail('Should not have throw');
});

it('should throw with HPE_INVALID_CONSTANT and then fail on retry', async () => {
let doPostStub = sinon.stub(rokuDeploy as any, 'doPostRequest');
doPostStub.onFirstCall().throws((params) => {
throw new ErrorWithCode();
});
doPostStub.onSecondCall().returns({ body: '..."fileType":"zip"...' });
try {
await rokuDeploy.convertToSquashfs(options);
} catch (e) {
expect(e).to.be.instanceof(errors.ConvertError);
return;
}
assert.fail('Should not have throw');
});

it('should fail with HPE_INVALID_CONSTANT and then throw on retry', async () => {
let doPostStub = sinon.stub(rokuDeploy as any, 'doPostRequest');
doPostStub.onFirstCall().throws((params) => {
throw new ErrorWithCode();
});
doPostStub.onSecondCall().throws((params) => {
throw new Error('Never seen');
});
try {
await rokuDeploy.convertToSquashfs(options);
} catch (e) {
expect(e).to.be.instanceof(ErrorWithCode);
return;
}
assert.fail('Should not have throw');
});
});

class ErrorWithCode extends Error {
code;

constructor(code = 'HPE_INVALID_CONSTANT') {
super();
this.code = code;
}
}

describe('rekeyDevice', () => {
beforeEach(() => {
const body = `<device-info>
Expand Down
23 changes: 21 additions & 2 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,27 @@ export class RokuDeploy {
archive: '',
mysubmit: 'Convert to squashfs'
});

let results = await this.doPostRequest(requestOptions);
let results;
try {
results = await this.doPostRequest(requestOptions);
} catch (error) {
//Occasionally this error is seen if the zip size and file name length at the
//wrong combination. The device fails to respond to our request with a valid response.
//The device successfully converted the zip, so ping the device and and check the response
//for "fileType": "squashfs" then return a happy response, otherwise throw the original error
if ((error as any).code === 'HPE_INVALID_CONSTANT') {
try {
results = await this.doPostRequest(requestOptions, false);
if (/"fileType"\s*:\s*"squashfs"/.test(results.body)) {
return results;
}
} catch (e) {
throw error;
}
} else {
throw error;
}
}
if (results.body.indexOf('Conversion succeeded') === -1) {
throw new errors.ConvertError('Squashfs conversion failed');
}
Expand Down

0 comments on commit 1b4f73e

Please sign in to comment.