Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improved timeout err msg #909

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,14 @@
label="IDF Process Console">
</consoleFactory>
</extension>
<extension
point="org.eclipse.debug.core.statusHandlers">
<statusHandler
class="com.espressif.idf.debug.gdbjtag.openocd.ui.OpenocdStatusHandler"
code="5012"
id="com.espressif.idf.debug.gdbjtag.openocd.openocdStatusHandler"
plugin="com.espressif.idf.debug.gdbjtag.openocd">
</statusHandler>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*******************************************************************************

Check warning on line 1 in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/LaunchConfigurationDelegate.java

View workflow job for this annotation

GitHub Actions / spotbugs

THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION

Method lists Exception in its throws clause.
Raw output
Method lists Exception in its throws clause.
When declaring a method, the types of exceptions in the throws clause should be the most specific. Therefore, using Exception in the throws clause would force the caller to either use it in its own throws clause, or use it in a try-catch block (when it does not necessarily contain any meaningful information about the thrown exception).

For more information, see the SEI CERT ERR07-J rule [https://wiki.sei.cmu.edu/confluence/display/java/ERR07-J.+Do+not+throw+RuntimeException%2C+Exception%2C+or+Throwable].
* Copyright (c) 2013 Liviu Ionescu.
*
* This program and the accompanying materials
Expand Down Expand Up @@ -49,6 +49,7 @@
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
Expand Down Expand Up @@ -208,8 +209,8 @@
try
{
stream = process.getInputStream();
Reader r = new InputStreamReader(stream);

Check warning on line 212 in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/LaunchConfigurationDelegate.java

View workflow job for this annotation

GitHub Actions / spotbugs

DM_DEFAULT_ENCODING

Found reliance on default encoding in com.espressif.idf.debug.gdbjtag.openocd.dsf.LaunchConfigurationDelegate.getGDBVersion(ILaunchConfiguration, String): new java.io.InputStreamReader(InputStream)
Raw output
Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behavior to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.
BufferedReader reader = new BufferedReader(r);

Check warning on line 213 in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/LaunchConfigurationDelegate.java

View workflow job for this annotation

GitHub Actions / spotbugs

OS_OPEN_STREAM

com.espressif.idf.debug.gdbjtag.openocd.dsf.LaunchConfigurationDelegate.getGDBVersion(ILaunchConfiguration, String) may fail to close stream
Raw output
The method creates an IO stream object, does not assign it to any fields, pass it to other methods that might close it, or return it, and does not appear to close the stream on all paths out of the method.  This may result in a file descriptor leak.  It is generally a good idea to use a finally block to ensure that streams are closed.

String line;
while ((line = reader.readLine()) != null)
Expand Down Expand Up @@ -446,8 +447,19 @@
}
catch (ExecutionException e1)
{
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
"Error in services launch sequence", e1.getCause())); //$NON-NLS-1$
if (e1.getMessage().contains("Starting OpenOCD timed out.")) //$NON-NLS-1$
{
IStatus status = new Status(IStatus.OK, Activator.PLUGIN_ID, DebugException.REQUEST_FAILED,
"Error in services launch sequence", e1.getCause()); //$NON-NLS-1$
DebugPlugin.getDefault().getStatusHandler(status).handleStatus(status, null);
throw new DebugException(Status.OK_STATUS);
}
else
{
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
"Error in services launch sequence", e1.getCause())); //$NON-NLS-1$
}

}
catch (CancellationException e1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
public static String TabMain_Launch_Config;

public static String TabDebugger_SettingTargetJob;

public static String OpenOCDConsole_ErrorGuideMessage;

public static String TabDebugger_noConfigOptions;
Expand All @@ -71,6 +71,10 @@
public static String TabDebugger_noTclPort;
public static String TabDebugger_noTelnetPort;

public static String ServerTimeoutErrorDialog_title;
public static String ServerTimeoutErrorDialog_message;
public static String ServerTimeoutErrorDialog_customAreaMessage;

// ------------------------------------------------------------------------

static
Expand Down Expand Up @@ -111,7 +115,7 @@

public static ResourceBundle getResourceBundle()
{
return RESOURCE_BUNDLE;

Check warning on line 118 in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/Messages.java

View workflow job for this annotation

GitHub Actions / spotbugs

MS_EXPOSE_REP

Public static com.espressif.idf.debug.gdbjtag.openocd.ui.Messages.getResourceBundle() may expose internal representation by returning Messages.RESOURCE_BUNDLE
Raw output
A public static method returns a reference to an array that is part of the static state of the class. Any code that calls this method can freely modify the underlying array. One fix is to return a copy of the array.
}

// ------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.debug.gdbjtag.openocd.ui;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.dialogs.PreferencesUtil;

public class OpenocdStatusHandler implements IStatusHandler
{
private static final String ESPRESSIF_PREFERENCES_MAINPAGE_ID = "com.espressif.idf.ui.preferences.mainpage"; //$NON-NLS-1$

public Object handleStatus(IStatus status, Object source) throws CoreException
{
Display.getDefault().asyncExec(() -> {
MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
Messages.ServerTimeoutErrorDialog_title, null, Messages.ServerTimeoutErrorDialog_message,
MessageDialog.ERROR, 0, IDialogConstants.OK_LABEL)
{
@Override
public Control createCustomArea(Composite parent)
{
Link link = new Link(parent, SWT.WRAP);
link.setText(Messages.ServerTimeoutErrorDialog_customAreaMessage);
link.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
PreferencesUtil.createPreferenceDialogOn(parent.getShell(),
ESPRESSIF_PREFERENCES_MAINPAGE_ID, null, null).open();
}
});
return link;
}

};
dialog.open();
});
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,9 @@ TabMain_Launch_Config=Launch Configuration:


## Console Messages ##
OpenOCDConsole_ErrorGuideMessage=Please refer to the troubleshooting guide below to identify the problem.
OpenOCDConsole_ErrorGuideMessage=Please refer to the troubleshooting guide below to identify the problem.

## Timeout Exception Dialog ##
ServerTimeoutErrorDialog_customAreaMessage=To increase timeout time visit <a>the Espressif Preference Page</a>.
ServerTimeoutErrorDialog_message=Starting OpenOCD timed out. Try to increase the `GDB server launch timeout`
ServerTimeoutErrorDialog_title=Problem Occurred
Loading