Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[cli] better build errors #1928

Merged
merged 1 commit into from
Apr 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 98 additions & 46 deletions packages/expo-cli/src/commands/build/ios/IOSBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
getProvisioningProfileFromParams,
useProvisioningProfileFromParams,
} from '../../../credentials/views/IosProvisioningProfile';
import { IosAppCredentials, IosDistCredentials } from '../../../credentials/credentials';

class IOSBuilder extends BaseBuilder {
appleCtx?: apple.AppleCtx;
Expand Down Expand Up @@ -144,21 +145,102 @@ See https://docs.expo.io/versions/latest/distribution/building-standalone-apps/#
ErrorCodes.NON_INTERACTIVE,
'Unable to proceed, see the above error message.'
);
}

log(
chalk.bold.red(
'Failed to prepare all credentials. \nThe next time you build, we will automatically use the following configuration:'
)
);
throw e;
} finally {
const credentials = await context.ios.getAllCredentials();
displayProjectCredentials(experienceName, bundleIdentifier, credentials);
}
}

async _setupDistCert(
ctx: Context,
experienceName: string,
bundleIdentifier: string,
appCredentials: IosAppCredentials
): Promise<void> {
try {
const nonInteractive = this.options.parent && this.options.parent.nonInteractive;
const distCertFromParams = await getDistCertFromParams(this.options);
if (distCertFromParams) {
await useDistCertFromParams(ctx, appCredentials, distCertFromParams);
} else {
log(
chalk.bold.red(
'Failed to prepare all credentials. \nThe next time you build, we will automatically use the following configuration:'
)
await runCredentialsManager(
ctx,
new SetupIosDist({ experienceName, bundleIdentifier, nonInteractive })
);
}
} catch (e) {
log.error('Failed to set up Distribution Certificate');
throw e;
}
}

const credentials = await context.ios.getAllCredentials();
displayProjectCredentials(experienceName, bundleIdentifier, credentials);
async _setupPushCert(
ctx: Context,
experienceName: string,
bundleIdentifier: string,
appCredentials: IosAppCredentials
): Promise<void> {
try {
const nonInteractive = this.options.parent && this.options.parent.nonInteractive;
const pushKeyFromParams = await getPushKeyFromParams(this.options);
if (pushKeyFromParams) {
await usePushKeyFromParams(ctx, appCredentials, pushKeyFromParams);
} else {
await runCredentialsManager(
ctx,
new SetupIosPush({ experienceName, bundleIdentifier, nonInteractive })
);
}
} catch (e) {
log.error('Failed to set up Push Key');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any more context that we can provide in this error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more context-specific error with the expo.fyi link is caught and rethrown (which will then print to stderr). I catch it at this point and print out Failed to set up Push Key so we know which part of the credential process we failed at. The error logging would look something like this:

Failed to set up Push Key
Additional information needed to setup credentials in non-interactive mode.
Learn more about how to resolve this: expo.fyi/credentials-non-interactive (​https://expo.fyi/credentials-non-interactive​).

throw e;
}
}

async _setupProvisioningProfile(
ctx: Context,
experienceName: string,
bundleIdentifier: string,
appCredentials: IosAppCredentials,
distributionCert: IosDistCredentials
) {
try {
const nonInteractive = this.options.parent && this.options.parent.nonInteractive;
const provisioningProfileFromParams = await getProvisioningProfileFromParams(this.options);
if (provisioningProfileFromParams) {
await useProvisioningProfileFromParams(
ctx,
appCredentials,
this.options.teamId!,
provisioningProfileFromParams,
distributionCert
);
} else {
await runCredentialsManager(
ctx,
new SetupIosProvisioningProfile({
experienceName,
bundleIdentifier,
distCert: distributionCert,
nonInteractive,
})
);
}
} catch (e) {
log.error('Failed to set up Provisioning Profile');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to above, is there any more context we can provide here? maybe a expo.fyi link that explains why this can happen, for example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comment :)

throw e;
}
}

async produceCredentials(ctx: Context, experienceName: string, bundleIdentifier: string) {
const nonInteractive = this.options.parent && this.options.parent.nonInteractive;
const appCredentials = await ctx.ios.getAppCredentials(experienceName, bundleIdentifier);

if (ctx.hasAppleCtx()) {
Expand All @@ -168,16 +250,7 @@ See https://docs.expo.io/versions/latest/distribution/building-standalone-apps/#
{ enablePushNotifications: true }
);
}

const distCertFromParams = await getDistCertFromParams(this.options);
if (distCertFromParams) {
await useDistCertFromParams(ctx, appCredentials, distCertFromParams);
} else {
await runCredentialsManager(
ctx,
new SetupIosDist({ experienceName, bundleIdentifier, nonInteractive })
);
}
await this._setupDistCert(ctx, experienceName, bundleIdentifier, appCredentials);

const distributionCert = await ctx.ios.getDistCert(experienceName, bundleIdentifier);
if (!distributionCert) {
Expand All @@ -187,36 +260,15 @@ See https://docs.expo.io/versions/latest/distribution/building-standalone-apps/#
);
}

const pushKeyFromParams = await getPushKeyFromParams(this.options);
if (pushKeyFromParams) {
await usePushKeyFromParams(ctx, appCredentials, pushKeyFromParams);
} else {
await runCredentialsManager(
ctx,
new SetupIosPush({ experienceName, bundleIdentifier, nonInteractive })
);
}
await this._setupPushCert(ctx, experienceName, bundleIdentifier, appCredentials);

const provisioningProfileFromParams = await getProvisioningProfileFromParams(this.options);
if (provisioningProfileFromParams) {
await useProvisioningProfileFromParams(
ctx,
appCredentials,
this.options.teamId!,
provisioningProfileFromParams,
distributionCert
);
} else {
await runCredentialsManager(
ctx,
new SetupIosProvisioningProfile({
experienceName,
bundleIdentifier,
distCert: distributionCert,
nonInteractive,
})
);
}
await this._setupProvisioningProfile(
ctx,
experienceName,
bundleIdentifier,
appCredentials,
distributionCert
);
}

async clearAndRevokeCredentialsIfRequested(ctx: Context, projectMetadata: any): Promise<void> {
Expand Down