Skip to content

Commit

Permalink
fix: pass Android manifest parse errors through to the user (#1270)
Browse files Browse the repository at this point in the history
* fix: pass Android manifest parse errors through; remove manual link warnings

* bring warnings back

* fix prettier

* remove try/catch; move projectConfig retrieval outside of for loop

* remove debug logs
  • Loading branch information
thymikee authored Sep 21, 2020
1 parent 83ef467 commit 652ab45
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/templateName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function processTemplateName(templateName: string) {
return handleVersionedPackage(templateName);
}
if (
!['github', '@'].some(str => templateName.includes(str)) &&
!['github', '@'].some((str) => templateName.includes(str)) &&
templateName.includes('/')
) {
return handleGitHubRepo(templateName);
Expand Down
15 changes: 9 additions & 6 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ const handleError = (err: Error) => {
} else {
// Some error messages (esp. custom ones) might have `.` at the end already.
const message = err.message.replace(/\.$/, '');
logger.error(
`${message}. ${chalk.dim(
logger.error(`${message}.`);
}
if (err.stack) {
logger.log(err.stack);
}
if (!commander.verbose) {
logger.info(
chalk.dim(
`Run CLI with ${chalk.reset('--verbose')} ${chalk.dim(
'flag for more details.',
)}`,
)}`,
),
);
}
if (err.stack) {
logger.log(chalk.dim(err.stack));
}
process.exit(1);
};

Expand Down
11 changes: 9 additions & 2 deletions packages/platform-android/src/config/readManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
* LICENSE file in the root directory of this source tree.
*
*/

import fs from 'fs';
import xml from 'xmldoc';
import {CLIError} from '@react-native-community/cli-tools';

export default function readManifest(manifestPath: string) {
return new xml.XmlDocument(fs.readFileSync(manifestPath, 'utf8'));
try {
return new xml.XmlDocument(fs.readFileSync(manifestPath, 'utf8'));
} catch (error) {
throw new CLIError(
`Failed to parse Android Manifest file at ${manifestPath}`,
error,
);
}
}
23 changes: 10 additions & 13 deletions packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ export default function warnAboutManuallyLinkedLibs(
> = getLinkConfig(),
) {
let deps: Array<string> = [];
const projectConfig = config.project[platform];

for (let key in config.dependencies) {
const dependency = config.dependencies[key];
try {
const projectConfig = config.project[platform];
const dependencyConfig = dependency.platforms[platform];
if (projectConfig && dependencyConfig) {
const x = linkConfig.isInstalled(
projectConfig,
dependency.name,
dependencyConfig,
);
deps = deps.concat(x ? dependency.name : []);
}
} catch (error) {
logger.debug('Checking manually linked modules failed.', error);

const dependencyConfig = dependency.platforms[platform];
if (projectConfig && dependencyConfig) {
const x = linkConfig.isInstalled(
projectConfig,
dependency.name,
dependencyConfig,
);
deps = deps.concat(x ? dependency.name : []);
}
}

Expand Down
23 changes: 10 additions & 13 deletions packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ export default function warnAboutManuallyLinkedLibs(
> = getLinkConfig(),
) {
let deps: Array<string> = [];
const projectConfig = config.project[platform];

for (let key in config.dependencies) {
const dependency = config.dependencies[key];
try {
const projectConfig = config.project[platform];
const dependencyConfig = dependency.platforms[platform];
if (projectConfig && dependencyConfig) {
const x = linkConfig.isInstalled(
projectConfig,
dependency.name,
dependencyConfig,
);
deps = deps.concat(x ? dependency.name : []);
}
} catch (error) {
logger.debug('Checking manually linked modules failed.', error);

const dependencyConfig = dependency.platforms[platform];
if (projectConfig && dependencyConfig) {
const x = linkConfig.isInstalled(
projectConfig,
dependency.name,
dependencyConfig,
);
deps = deps.concat(x ? dependency.name : []);
}
}

Expand Down

0 comments on commit 652ab45

Please sign in to comment.