Skip to content

Commit

Permalink
fix: many Exceptions logged if editor underlying resource (re)moved #661
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Jan 11, 2024
1 parent 854d55a commit 82cf7d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public static void logError(final Exception ex) {
log(new Status(IStatus.ERROR, PLUGIN_ID, ex.getMessage(), ex));
}

public static void logTrace(final Exception ex) {
if (isLogTraceEnabled()) {
log(new Status(IStatus.INFO, PLUGIN_ID, ex.getMessage(), ex));
}
}

public static void logTrace(final String message) {
if (isLogTraceEnabled()) {
log(new Status(IStatus.INFO, PLUGIN_ID, message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
*/
package org.eclipse.tm4e.ui.internal.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;

import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer;
Expand All @@ -38,7 +38,6 @@

/**
* {@link IContentType} utilities.
*
*/
public final class ContentTypeHelper {

Expand Down Expand Up @@ -125,16 +124,13 @@ private static ContentTypeInfo getContentTypes(final ITextFileBuffer buffer) {

// Buffer is synchronized with filesystem content
try (InputStream contents = getContents(buffer)) {
contentTypes.addAll(
Arrays.asList(Platform.getContentTypeManager().findContentTypesFor(contents, fileName)));
contentTypes.addAll(List.of(Platform.getContentTypeManager().findContentTypesFor(contents, fileName)));
return new ContentTypeInfo(fileName, contentTypes.toArray(IContentType[]::new));
} catch (final Exception e) {
return null;
}
} catch (final CoreException | IOException ex) {
TMUIPlugin.logError(ex);
return null;
} catch (final Exception ex) {
TMUIPlugin.logTrace(ex);
}
return null;
}

/**
Expand Down Expand Up @@ -181,7 +177,8 @@ private static ContentTypeInfo findContentTypesFromEditorInput(final IDocument d
final var contentTypes = Platform.getContentTypeManager().findContentTypesFor(input, fileName);
return contentTypes == null ? null : new ContentTypeInfo(fileName, contentTypes);
}
} catch (final Exception e) {
} catch (final Exception ex) {
TMUIPlugin.logTrace(ex);
return null;
}
} /*else {
Expand Down Expand Up @@ -223,13 +220,13 @@ private static IEditorInput getEditorInput(final IDocument document) {
if (input instanceof final IEditorInput editorInput) {
return editorInput;
}
} catch (final RuntimeException e) {
e.printStackTrace();
} catch (final RuntimeException ex) {
TMUIPlugin.logTrace(ex);
}
}
}
} catch (final RuntimeException e) {
e.printStackTrace();
} catch (final RuntimeException ex) {
TMUIPlugin.logTrace(ex);
}
return null;
}
Expand Down

0 comments on commit 82cf7d9

Please sign in to comment.