本文整理匯總了TypeScript中loglevel.error函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript error函數的具體用法?TypeScript error怎麽用?TypeScript error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了error函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: onChange
// error handling taken from https://webpack.github.io/docs/node.js-api.html#error-handling
function onChange(err, stats, livereloadServer, onChangeSuccess?) {
if (err) {
// "hard" error
return error(err);
}
if (stats.hasErrors()) {
// "soft" error
return error(stats.toString(statsStringifierOptions));
}
if (stats.hasWarnings()) {
warn(stats.toString(statsStringifierOptions));
}
// filter changes for live reloading
const changedModules = stats.compilation.modules.filter(module => module.built && module.resource);
const changedStyleModules = changedModules.filter(module => module.resource.match(/\.(css|less|sass)$/));
let hasOnlyStyleChanges = changedModules.length === changedStyleModules.length;
if (hasOnlyStyleChanges) {
livereloadServer.refresh('style.css');
} else {
livereloadServer.refresh('index.html');
}
if (onChangeSuccess) {
onChangeSuccess(stats);
}
}
示例2: handleError
export function handleError(err: Error) {
if (err.stack) {
err.stack.split('\n')
.filter(line => !IGNORED_TRACE_LINES.some(ignoredLine => line.includes(ignoredLine)))
.forEach(line => error(line));
} else {
error(err);
}
error(`${red('error!')} ( ╯°□°)╯ ┻━━┻`);
process.exit(1);
}
示例3: onChange
// error handling taken from https://webpack.github.io/docs/node.js-api.html#error-handling
async function onChange(
err: any,
stats: compiler.Stats,
livereloadServer: Server,
onChangeSuccess?: any
) {
if (err) {
// "hard" error
return error(err);
}
if (stats.hasErrors()) {
// "soft" error
return error(stringifyStats(stats));
}
if (stats.hasWarnings()) {
warn(stringifyStats(stats));
}
if (isVerbose()) {
info(stringifyStats(stats));
}
if (onChangeSuccess) {
await onChangeSuccess(stats);
}
// filter changes for live reloading
const modules = getModules(stats);
const changedModules = modules.filter(
module => module.built && module.resource
);
const changedStyleModules = changedModules.filter(module =>
module.resource.match(/\.(css|less|sass)$/)
);
const hasOnlyStyleChanges =
changedModules.length === changedStyleModules.length;
if (hasOnlyStyleChanges) {
livereloadServer.refresh('style.css');
} else {
livereloadServer.refresh('index.html');
}
}
示例4: lint
export default async function lint() {
// typescript
const typescriptFileFailures = await lintAsync();
if (typescriptFileFailures.length) {
// log all failures with some basic formatting
error('');
for (const fileFailure of typescriptFileFailures) {
error(`Found ${yellow(fileFailure.failureCount.toString())} failure(s) in ${yellow(fileFailure.failures[0].getFileName())}:`);
for (const failure of fileFailure.failures) {
const fileName = failure.getFileName();
if (!sourceFileLines[fileName]) {
// attention: sourceFile is a private property!
sourceFileLines[fileName] = (failure as any).sourceFile.text.split('\n');
}
const lines = sourceFileLines[fileName];
const { line, character } = failure.getStartPosition().getLineAndCharacter();
error(` ${failure.getFailure()} ${grey(`(at [${line + 1}:${character + 1}]: ${lines[line].trim()})`)}`);
}
error('');
}
}
// documentation
const documentationFailures = [];
if (!project.private) {
if (!(await existsAsync(join(process.cwd(), 'README.md')))) {
documentationFailures.push(`You have ${yellow('no README.md')}.`);
}
if (!project.keywords || !project.keywords.length) {
documentationFailures.push(`You have ${yellow('no keywords')} set in your ${yellow('package.json')}.`);
}
if (!(await existsAsync(join(process.cwd(), 'examples')))) {
documentationFailures.push(`You have ${yellow('no examples/')} directory.`);
} else {
const contents = (await readdirAsync(join(process.cwd(), 'examples'))).filter(content => content !== '.DS_Store');
if (!contents.length) {
documentationFailures.push(`Your ${yellow('examples/')} directory ${yellow('is empty')}.`);
}
}
}
if (documentationFailures.length) {
error('');
error(`You're project ${yellow(`isn't private`)}, but it has ${yellow(documentationFailures.length.toString())} documentation failure(s).`);
documentationFailures.forEach(msg => error(` ${msg}`));
error('');
}
if (typescriptFileFailures.length || documentationFailures.length) {
throw `${cyan('lint')} failed.`;
}
};
示例5: handleError
export function handleError(err: Error) {
if (err.stack) {
err.stack
.split('\n')
.filter(
line =>
!IGNORED_TRACE_LINES.some(ignoredLine => line.includes(ignoredLine))
)
.filter((_, index) => index < 6) // roughly error message + 5 code lines
.map(line => line.replace('webpack:///', './'))
.map(line => line.replace(`${__dirname}/webpack:/`, './'))
.forEach(line => error(line));
} else {
error(err);
}
error(`${red('error!')} ( ╯°□°)╯ ┻━━┻`);
process.exitCode = 1;
// call process.exit with a slight delay to reduce risk of trimmed error logs
// (e.g. if you call process.exit directly there is a change that some
// console.log's aren't printed to the console - but we *want* to process.exit,
// because some commands create server/background tasks which aren't closed otherwise)
setTimeout(process.exit, 1);
}
示例6: format
filePaths.map(async (filePath, index) => {
const content = contents[index];
let formattedContent;
try {
formattedContent = format(content, options);
} catch (err) {
error(`Couldn't format ${red(filePath)}.`);
throw err;
}
if (content !== formattedContent) {
fixedFiles.push(filePath);
await writeFileAsync(filePath, formattedContent);
}
})
示例7: template
function template():string {
switch (PlatformTools.getTargetPlatforrm()) {
case TargetPlatformId.IONIC:
return `
<ion-list>
<form>
<ion-list-header>
Start New Game
</ion-list-header>
<ion-item>
<ion-label for="password">Password (optional):</ion-label>
<ion-input class="form-control" [(ngModel)]="password" type="text" id="password"></ion-input>
</ion-item>
<ion-item>
<button large block (click)="newGame()">
Start Game
</button>
</ion-item>
</form>
</ion-list>
`;
case TargetPlatformId.TWBS_CORDOVA:
case TargetPlatformId.TWBS_WEB:
return `
<div>
<form>
<div class="panel-heading">
<h2 class="panel-title">Start New Game</h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="password">Password (optional):</label>
<input class="form-control" [(ngModel)]="password" name="password" type="text" id="password">
</div>
<button type="button" class="btn btn-success btn-block" (click)="newGame()">
Start Game
</button>
</div>
</form>
</div>
`;
default:
log.error('Styling not developed for target platform')
}
}
示例8: logError
export function logError(msg: string, ...otherArgs: any[]) {
return log.error(`Error: ${msg}`, ...otherArgs)
}
示例10: error
documentationFailures.forEach(msg => error(` ${msg}`));