Compare commits

...
9 changed files with 171 additions and 24 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
'eas-cli': minor
---
Report `EAS_INPUT_REQUIRED` when a non-interactive fingerprint comparison needs a selection.
+5
View File
@@ -0,0 +1,5 @@
---
'eas-cli': minor
---
Report `EAS_PERMISSION_DENIED` in JSON output when the API denies access.
+10
View File
@@ -88,6 +88,16 @@ 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. |
| `EAS_INPUT_REQUIRED` | For `fingerprint:compare`, provide a fingerprint hash, build ID, or individual update ID, or rerun interactively to choose. |
## 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.
@@ -0,0 +1,31 @@
const nock = require('nock');
nock.disableNetConnect();
const api = nock('http://127.0.0.1:3000').persist();
api
.post('/graphql', body => body.query.includes('query CurrentUser'))
.reply(200, {
data: { meActor: { __typename: 'User', id: 'me', username: 'fixture', accounts: [] } },
});
api
.post('/graphql', body => body.query.includes('query AppByIdQuery'))
.reply(200, (_uri, body) => {
if (process.env.EXPO_TOKEN === 'denied-token') {
return {
errors: [{ message: 'Fixture refusal', extensions: { errorCode: 'UNAUTHORIZED_ERROR' } }],
};
}
return {
data: {
app: {
byId: { id: body.variables.appId, slug: 'fixture', ownerAccount: { name: 'fixture' } },
},
},
};
});
api
.post('/graphql', body => body.query.includes('query ViewUpdatesByGroup'))
.reply(200, {
data: { updatesByGroup: [{ id: 'ios-update' }, { id: 'android-update' }] },
});
+10
View File
@@ -88,6 +88,16 @@ 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. |
| `EAS_INPUT_REQUIRED` | For `fingerprint:compare`, provide a fingerprint hash, build ID, or individual update ID, or rerun interactively to choose. |
## 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', []],
@@ -0,0 +1,67 @@
import { spawnSync } from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
describe('fingerprint:compare --json', () => {
it.each([
{ code: 'EAS_LOGIN_REQUIRED', token: undefined, args: ['--build-id', 'build-id'] },
{ code: 'EAS_PERMISSION_DENIED', token: 'denied-token', args: ['--build-id', 'build-id'] },
{ code: 'EAS_INPUT_REQUIRED', token: 'allowed-token', args: [] },
{ code: 'EAS_INPUT_REQUIRED', token: 'allowed-token', args: ['--update-id', 'group-id'] },
])('returns $code for $args', ({ code, token, args }) => {
const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), 'eas-fingerprint-'));
try {
fs.writeFileSync(path.join(projectDir, 'package.json'), '{"name":"fixture"}');
fs.writeFileSync(
path.join(projectDir, 'app.json'),
JSON.stringify({
expo: {
name: 'fixture',
slug: 'fixture',
sdkVersion: '56.0.0',
extra: { eas: { projectId: '00000000-0000-4000-8000-000000000001' } },
},
})
);
// The update check reads this cache before deciding whether to spawn a registry lookup.
fs.writeFileSync(path.join(projectDir, 'version'), '{}');
const result = spawnSync(
process.execPath,
[
'--require',
require.resolve('../../../../jest/fingerprintProject.cjs'),
path.resolve(__dirname, '../../../../bin/dev'),
'fingerprint:compare',
...args,
'--json',
],
{
cwd: projectDir,
env: {
PATH: process.env.PATH,
HOME: projectDir,
USERPROFILE: projectDir,
EAS_CACHE_DIR: projectDir,
EAS_PROJECT_ROOT: projectDir,
EAS_NO_VCS: '1',
EXPO_LOCAL: '1',
EXPO_NO_TELEMETRY: '1',
EXPO_TOKEN: token,
CI: '1',
NO_COLOR: '1',
},
timeout: 60000,
encoding: 'utf8',
}
);
expect(result.error).toBeUndefined();
expect(result.status).toBe(1);
expect(JSON.parse(result.stdout)).toMatchObject({
error: { code, message: expect.any(String) },
});
} finally {
fs.rmSync(projectDir, { recursive: true, force: true });
}
});
});
@@ -8,6 +8,7 @@ import EasCommand from '../../commandUtils/EasCommand';
import { fetchBuildsAsync, formatBuild } from '../../commandUtils/builds';
import { GetServerSideEnvironmentVariablesFn } from '../../commandUtils/context/ServerSideEnvironmentVariablesContextField';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { EasCommandError } from '../../commandUtils/errors';
import {
EasEnvironmentFlagParameters,
EasNonInteractiveAndJsonFlags,
@@ -343,8 +344,9 @@ async function getFingerprintInfoAsync(
}
if (nonInteractive) {
throw new Error(
'Insufficent arguments provided for fingerprint comparison in non-interactive mode'
throw new EasCommandError(
'Pass a fingerprint hash, --build-id, or --update-id to compare in non-interactive mode.',
{ code: 'EAS_INPUT_REQUIRED' }
);
}
return await getFingerprintInfoInteractiveAsync({
@@ -572,8 +574,9 @@ async function getFingerprintInfoFromUpdateGroupIdOrUpdateIdAsync(
const updateUrl =
getExpoWebsiteBaseUrl() +
`/accounts/${project.ownerAccount.name}/projects/${project.slug}/updates/${maybeUpdateGroupId}`;
throw new Error(
`Please pass in your update ID from ${updateUrl} or use interactive mode to select the update ID.`
throw new EasCommandError(
`Please pass in your update ID from ${updateUrl} or use interactive mode to select the update ID.`,
{ code: 'EAS_INPUT_REQUIRED' }
);
}
const update = await selectAsync<UpdateFragment>(