Skip to content

Commit

Permalink
[eas-cli] [ENG-7536] Stop app config error repeating (#2020)
Browse files Browse the repository at this point in the history
* [eas-cli] Stop app config error repeating

If app config error is thrown it is re-thrown with modified message instead of printing it to the as a "cryptic error" and repeating with 0% chances of success (since the config is incorrect)

See: https://linear.app/expo/issue/ENG-7536/make-app-config-error-on-credentials-command-not-repeat-indefinitely

* [eas-cli] Create custom error

Replaced generic error with specific message with a custom error class, which allows for not relying on a message to be exactly as expected

See: https://linear.app/expo/issue/ENG-7536/make-app-config-error-on-credentials-command-not-repeat-indefinitely

* update CHANGELOG.md

* [eas-cli] Remove blank line

Removed blank line from changelog

See: https://linear.app/expo/issue/ENG-7536/make-app-config-error-on-credentials-command-not-repeat-indefinitely
  • Loading branch information
radoslawkrzemien committed Aug 30, 2023
1 parent 324dce8 commit 9ff47af
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🐛 Bug fixes

- Make app config error not repeat indefinitely. ([#2020](https://github.com/expo/eas-cli/pull/2020) by [@radoslawkrzemien](https://github.com/radoslawkrzemien))

### 🧹 Chores

## [5.0.2](https://github.com/expo/eas-cli/releases/tag/v5.0.2) - 2023-08-29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../../../project/projectUtils';
import { promptAsync } from '../../../prompts';
import { CredentialsContext } from '../../context';
import { AndroidPackageNotDefinedError } from '../../errors';
import { AppLookupParams } from '../api/GraphqlClient';

/**
Expand Down Expand Up @@ -111,7 +112,7 @@ export async function getAppLookupParamsFromContextAsync(
gradleContext
);
if (!androidApplicationIdentifier) {
throw new Error(
throw new AndroidPackageNotDefinedError(
`android.package needs to be defined in your ${getProjectConfigDescription(
ctx.projectDir
)} file`
Expand Down
6 changes: 6 additions & 0 deletions packages/eas-cli/src/credentials/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ export class UnsupportedCredentialsChoiceError extends Error {
super(message);
}
}

export class AndroidPackageNotDefinedError extends Error {
constructor(message?: string) {
super(message ?? 'android.package needs to be defined in your app.json/app.config.js file');
}
}
7 changes: 7 additions & 0 deletions packages/eas-cli/src/credentials/manager/ManageAndroid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
displayEmptyAndroidCredentials,
} from '../android/utils/printCredentials';
import { CredentialsContext, CredentialsContextProjectInfo } from '../context';
import { AndroidPackageNotDefinedError } from '../errors';
import { ActionInfo, AndroidActionType, Scope } from './Actions';
import {
buildCredentialsActions,
Expand Down Expand Up @@ -131,6 +132,12 @@ export class ManageAndroid {

await this.runProjectSpecificActionAsync(ctx, chosenAction, gradleContext);
} catch (err) {
if (err instanceof AndroidPackageNotDefinedError) {
err.message += `\n${learnMore(
'https://docs.expo.dev/workflow/configuration/'
)} about configuration with app.json/app.config.js`;
throw err; // breaks out of the loop to avoid failing again after continuation
}
Log.error(err);
if (process.env.DEBUG) {
throw err; // breaks out of the loop so we can get stack trace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Platform } from '@expo/eas-build-job';
import { BuildProfile, EasJsonUtils } from '@expo/eas-json';

import { Analytics } from '../../../analytics/AnalyticsManager';
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient';
import { learnMore } from '../../../log';
import { getProjectConfigDescription } from '../../../project/projectUtils';
import { pressAnyKeyToContinueAsync } from '../../../prompts';
import { Actor } from '../../../user/User';
import { getAppLookupParamsFromContextAsync } from '../../android/actions/BuildCredentialsUtils';
import { CredentialsContextProjectInfo } from '../../context';
import { AndroidPackageNotDefinedError } from '../../errors';
import { Action } from '../HelperActions';
import { ManageAndroid } from '../ManageAndroid';

jest.mock('../../android/actions/BuildCredentialsUtils');
jest.mock('../../../prompts', () => {
return {
...jest.requireActual('../../../prompts'),
pressAnyKeyToContinueAsync: jest.fn(),
};
});
jest.mock('../../../project/projectUtils');

describe('runAsync', () => {
describe('"android.package" missing in app.json', () => {
const manageAndroid = new ManageAndroid(
{
projectInfo: {} as CredentialsContextProjectInfo,
actor: {} as Actor,
graphqlClient: {} as ExpoGraphqlClient,
analytics: {} as Analytics,
getDynamicPrivateProjectConfigAsync: jest
.fn()
.mockResolvedValue({ exp: {}, projectId: '' }),
runAsync: jest.fn(),
} as Action,
''
);
it('does not repeat the error indefinitely and prints useful error', async () => {
jest.spyOn(EasJsonUtils, 'getBuildProfileNamesAsync').mockResolvedValue(['testProfile']);
jest
.spyOn(EasJsonUtils, 'getBuildProfileAsync')
.mockResolvedValue({} as BuildProfile<Platform.ANDROID>);
jest.mocked(getProjectConfigDescription).mockReturnValue('app.json');
jest.mocked(getAppLookupParamsFromContextAsync).mockImplementation(() => {
throw new AndroidPackageNotDefinedError(
'Specify "android.package" in app.json and run this command again.'
);
});
const pressAnyKeyToContinueAsyncMock = jest.mocked(pressAnyKeyToContinueAsync);
Array.from(Array(100)).map((_, i) => {
// continue 101 times if error is rethrown indefinitely
pressAnyKeyToContinueAsyncMock.mockResolvedValueOnce();
});
pressAnyKeyToContinueAsyncMock.mockImplementationOnce(async () => {
// fail after 102nd time
fail('test should not reach this place - if it does, the error repeats indefinitely');
});
const reThrownError = new AndroidPackageNotDefinedError(
'Specify "android.package" in app.json and run this command again.\n' +
`${learnMore(
'https://docs.expo.dev/workflow/configuration/'
)} about configuration with app.json/app.config.js`
);
await expect(manageAndroid.runAsync()).rejects.toThrow(reThrownError);
});
});
});

0 comments on commit 9ff47af

Please sign in to comment.