private void onFailure(PromiseError error) { if (actionCompletedCallBack != null) { actionCompletedCallBack.onFailure(error.getCause()); } } }
/** Returns an operation which shows an error notification with the given title. */ private Operation<PromiseError> showErrorNotification(String title) { return err -> { notificationManager.notify(title, err.getMessage(), FAIL, EMERGE_MODE); throw new OperationException(err.getMessage()); }; }
public void findUsages(TextEditor editor) { if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) { return; } Document document = editor.getDocument(); TextDocumentPositionParams paramsDTO = dtoBuildHelper.createTDPP(document, editor.getCursorOffset()); Promise<UsagesResponse> promise = searchService.usages(paramsDTO); promise .then(this::handleResponse) .catchError( arg -> { Throwable cause = arg.getCause(); Log.error(getClass(), cause); manager.notify( localizationConstant.failedToProcessFindUsage(), arg.getMessage(), FAIL, FLOAT_MODE); }); }
.catchError( error -> { if (getErrorCode(error.getCause()) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) { dialogFactory .createMessageDialog( (error.getMessage() != null) ? error.getMessage() : constant.logFailed(); GitOutputConsole console = gitOutputConsoleFactory.create(LOG_COMMAND_NAME); console.printError(errorMessage);
/** * Called when children haven't been successfully loaded. Also fire {@link * org.eclipse.che.ide.ui.smartTree.event.LoadExceptionEvent} event. * * @param parent parent node, children which haven't been loaded * @return instance of {@link org.eclipse.che.api.promises.client.Operation} which contains * promise with error */ @NotNull private Operation<PromiseError> onLoadFailure(@NotNull final Node parent) { return error -> { childRequested.remove(parent); fireEvent(new LoadExceptionEvent(parent, error.getCause())); }; }
@Override public void apply(PromiseError arg) throws OperationException { notificationManager.notify( "Problems with getting classpath", arg.getMessage(), FAIL, EMERGE_MODE); } });
@Override protected Promise<Void> initAppContext() { return super.initAppContext() .thenPromise( aVoid -> getFactory() .then( (Function<FactoryDto, Void>) factory -> { ((AppContextImpl) appContext).setFactory(factory); return null; }) .catchError( (Operation<PromiseError>) err -> { throw new OperationException( "Unable to load Factory: " + err.getMessage(), err.getCause()); }) .then( arg -> { if (RUNNING != appContext.getWorkspace().getStatus()) { throw new OperationException( "Can't load Factory. Workspace is not running."); } })); }
@Override public Promise<Project> apply(PromiseError exception) throws FunctionException { subscriber.onFailure(exception.getCause().getMessage()); switch (getErrorCode(exception.getCause())) { case UNABLE_GET_PRIVATE_SSH_KEY: throw new IllegalStateException( localizationConstant.importProjectMessageUnableGetSshKey()); case UNAUTHORIZED_SVN_OPERATION: return recallImportWithCredentials(sourceStorage, path); case UNAUTHORIZED_GIT_OPERATION: final Map<String, String> attributes = ExceptionUtils.getAttributes(exception.getCause()); final String providerName = attributes.get(PROVIDER_NAME); final String authenticateUrl = attributes.get(AUTHENTICATE_URL); if (!Strings.isNullOrEmpty(providerName) && !Strings.isNullOrEmpty(authenticateUrl)) { return authUserAndRecallImport( providerName, authenticateUrl, path, sourceStorage, subscriber); } else { throw new IllegalStateException( localizationConstant.oauthFailedToGetAuthenticatorText()); } default: throw new IllegalStateException(exception.getCause()); } } });
/** Handle an error without IDE UI, as a fallback (when DialogFactory can't be used). */ private Operation<PromiseError> handleErrorFallback() { return err -> onInitializationFailed(err.getMessage()); }
@Override public Promise<Void> init() { return userInitializer .init() .catchError( (Operation<PromiseError>) err -> { // Fail to initialize the current user. // Since we can't get theme ID from the user's preferences // try to inject CSS styles with a default theme at least // in order to be able to use a minimal UI (dialogs) // for displaying an error information to the user. styleInjector.inject(); // Prevent further initialization steps. throw new OperationException(err.getMessage(), err.getCause()); }) .then(initUI()) .thenPromise(aVoid -> initAppContext()) .then(showUI()) .then( arg -> { eventBus.fireEvent(new BasicIDEInitializedEvent()); }); }
@Inject private void registerAllTemplates() { fetchTemplates() .then( templateDescriptors -> { templateDescriptors.forEach(this::register); }) .catchError( error -> { Log.error( ProjectTemplateRegistryImpl.this.getClass(), "Can't load project templates: " + error.getCause()); }); }
private Promise<Node> logError(PromiseError error) { Log.info(getClass(), error.getMessage()); return promises.resolve(null); }
private Promise<ProfileDto> loadProfile() { return getUserProfile() .catchError( (Operation<PromiseError>) arg -> { throw new OperationException("Unable to load user's profile: " + arg.getCause()); }); }
private Operation<PromiseError> logError() { return err -> view.showFactoryNameError( localizationConstant.createFactoryFromCurrentWorkspaceFailed(), err.getMessage()); }
private void registerProjectTypes() { fetchProjectTypes() .then( typeDescriptors -> { typeDescriptors.forEach( projectTypeDto -> projectTypes.put(projectTypeDto.getId(), projectTypeDto)); eventBus.fireEvent(new ProjectTypesLoadedEvent()); }) .catchError( error -> { Log.error( ProjectTypeRegistryImpl.this.getClass(), "Can't load project types: " + error.getCause()); }); }
@Override public void actionPerformed(ActionEvent e) { final Resource[] resources = appContext.getResources(); Set<String> pathsToExclude = stream(resources).map(resource -> resource.getLocation().toString()).collect(toSet()); fileWatcherExcludesOperation .addToFileWatcherExcludes(pathsToExclude) .catchError( error -> { notificationManager.notify(error.getMessage(), FAIL, EMERGE_MODE); }); }
private Promise<Map<String, String>> loadPreferences() { return preferencesManager .loadPreferences() .catchError( (Operation<PromiseError>) arg -> { throw new OperationException( messages.unableToLoadPreference() + ": " + arg.getCause()); }); }
@Override public void actionPerformed(ActionEvent e) { final Resource[] resources = appContext.getResources(); Set<String> pathsToRemove = stream(resources).map(resource -> resource.getLocation().toString()).collect(toSet()); fileWatcherExcludesOperation .removeFromFileWatcherExcludes(pathsToRemove) .catchError( error -> { notificationManager.notify(error.getMessage(), FAIL, EMERGE_MODE); }); }
Throwable throwable = error.getCause(); String errorMessage = throwable != null && !isNullOrEmpty(throwable.getLocalizedMessage())
/** Handle an error with IDE UI. */ private Operation<PromiseError> handleError() { return err -> { dialogFactory.createMessageDialog("IDE initialization failed", err.getMessage(), null).show(); Log.error(IdeBootstrap.class, err); }; }