Compare commits

..
5 changed files with 59 additions and 20 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
'eas-cli': minor
---
Report `EAS_PERMISSION_DENIED` in JSON output when the API denies access.
+9
View File
@@ -88,6 +88,15 @@ New to EAS? Follow [Create your first build](https://docs.expo.dev/build/setup/)
- **[EAS Metadata](https://docs.expo.dev/eas/metadata/)** (`eas metadata:push`): maintain your app store presence from the command line (in preview).
- **Project operations** (`eas env`, `eas credentials`, `eas device`, `eas channel`, …): manage environment variables, signing credentials, Apple devices, update channels, webhooks, and project settings.
## Handling JSON command failures
When an EAS command exits unsuccessfully with `--json`, read the optional `error.code` from stdout to choose a recovery. Display the diagnostic for unknown codes or for older CLI versions that omit the code or JSON output.
| Code | Recovery |
| --- | --- |
| `EAS_LOGIN_REQUIRED` | Sign in with `eas login` or provide an Expo access token in `EXPO_TOKEN`. |
| `EAS_PERMISSION_DENIED` | Verify the account and token have access to the requested resource. Ask the project owner for the required permissions. |
## Version policy
EAS CLI is designed to be installed globally or run with `npx`. Installing `eas-cli` into project dependencies is strongly discouraged because it can cause dependency conflicts that are difficult to debug.
@@ -88,6 +88,15 @@ New to EAS? Follow [Create your first build](https://docs.expo.dev/build/setup/)
- **[EAS Metadata](https://docs.expo.dev/eas/metadata/)** (`eas metadata:push`): maintain your app store presence from the command line (in preview).
- **Project operations** (`eas env`, `eas credentials`, `eas device`, `eas channel`, …): manage environment variables, signing credentials, Apple devices, update channels, webhooks, and project settings.
## Handling JSON command failures
When an EAS command exits unsuccessfully with `--json`, read the optional `error.code` from stdout to choose a recovery. Display the diagnostic for unknown codes or for older CLI versions that omit the code or JSON output.
| Code | Recovery |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `EAS_LOGIN_REQUIRED` | Sign in with `eas login` or provide an Expo access token in `EXPO_TOKEN`. |
| `EAS_PERMISSION_DENIED` | Verify the account and token have access to the requested resource. Ask the project owner for the required permissions. |
## Version policy
EAS CLI is designed to be installed globally or run with `npx`. Installing `eas-cli` into project dependencies is strongly discouraged because it can cause dependency conflicts that are difficult to debug.
@@ -300,6 +300,13 @@ export default abstract class EasCommand extends Command {
// Only codes that eas-cli sets. GraphQL error codes belong to the server and stay out.
code = err.code;
} else if (err instanceof CombinedError && err?.graphQLErrors) {
if (
!err.networkError &&
err.graphQLErrors.length > 0 &&
err.graphQLErrors.every(error => error.extensions?.errorCode === 'UNAUTHORIZED_ERROR')
) {
code = 'EAS_PERMISSION_DENIED';
}
const cleanGQLErrorsMessage = err?.graphQLErrors
.map((graphQLError: GraphQLError) => {
const messageLine = graphQLError.message.replace('[GraphQL] ', '');
@@ -423,29 +423,38 @@ describe('EasCommand', () => {
});
});
it('prints the GraphQL request ID, not the server error code', async () => {
const TestEasCommand = createJsonTestEasCommand();
const { printJsonErrorOutput } = jest.requireMock('../../utils/json');
const { CombinedError } = require('@urql/core');
const { GraphQLError } = require('graphql/error');
jest.spyOn(TestEasCommand.prototype, 'runAsync').mockImplementation(() => {
throw new CombinedError({
graphQLErrors: [
new GraphQLError('Entity not authorized', null, null, null, null, null, {
errorCode: 'UNAUTHORIZED_ERROR',
requestId: mockRequestId,
}),
],
it.each([
{ errors: ['UNAUTHORIZED_ERROR'], code: 'EAS_PERMISSION_DENIED' },
{ errors: ['UNKNOWN_GRAPHQL_ERROR'], code: undefined },
{ errors: ['UNAUTHORIZED_ERROR', 'UNKNOWN_GRAPHQL_ERROR'], code: undefined },
{ errors: ['UNAUTHORIZED_ERROR'], networkError: new Error('offline'), code: undefined },
])(
'maps $errors (network error: $networkError) to $code',
async ({ errors, code, networkError }) => {
const TestEasCommand = createJsonTestEasCommand();
const { printJsonErrorOutput } = jest.requireMock('../../utils/json');
const { CombinedError } = require('@urql/core');
const { GraphQLError } = require('graphql/error');
jest.spyOn(TestEasCommand.prototype, 'runAsync').mockImplementation(() => {
throw new CombinedError({
networkError,
graphQLErrors: errors.map(
errorCode =>
new GraphQLError('Request failed', null, null, null, null, null, {
errorCode,
requestId: mockRequestId,
})
),
});
});
});
await expect(TestEasCommand.run(['--json'], mockConfig)).rejects.toThrow();
await expect(TestEasCommand.run(['--json'], mockConfig)).rejects.toThrow();
expect(printJsonErrorOutput).toHaveBeenCalledWith(
expect.objectContaining({ requestId: mockRequestId })
);
expect(printJsonErrorOutput.mock.calls[0][0].code).toBeUndefined();
});
expect(printJsonErrorOutput).toHaveBeenCalledWith(
expect.objectContaining({ requestId: mockRequestId, code })
);
}
);
it.each([
['without --json', []],