Skip to content

Conversation

@Pepijn-DB
Copy link
Owner

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes error handling and logging in the LocationWebSocket mod by introducing a new file-based logging system, improving error recovery logic, and adding a configuration option to enable/disable the mod. The PR title contains a typo: "reseting" should be "resetting".

Key Changes

  • Added file-based error logging system with logErrors(), logInfo(), and logDebug() methods in Config.java
  • Implemented error recovery logic that removes errors from the error list when connections are re-established
  • Added enableMod configuration option to allow disabling the mod without removal

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/main/java/com/nyxz/fabric/locationwebsocket/mixin/TickEventsMixin.java Added null/enabled checks, dual logging (file + logger), and error recovery for UNKNOWN_ERROR
src/main/java/com/nyxz/fabric/locationwebsocket/handler/WebSocket.java Updated field references, added file-based logging, and implemented error recovery for WEBSOCKET_NOT_CONNECTED
src/main/java/com/nyxz/fabric/locationwebsocket/handler/ERRORS.java Added ERROR_FILE_WRITE_FAILURE enum value for file logging errors
src/main/java/com/nyxz/fabric/locationwebsocket/LocationWebSocket.java Changed config directory structure, improved error message formatting, and simplified list initialization
src/main/java/com/nyxz/fabric/locationwebsocket/Config.java Added file-based logging methods, enableMod field, error file handling, and new constructor for file writer initialization
gradle.properties Bumped mod version from 1.0.0 to 1.1.0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return enableMod;
}

public Writer getErrorFile() {
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name getErrorFile() suggests it returns a File object, but it actually returns a Writer. Consider renaming to getErrorWriter() or getErrorFileWriter() to better reflect what it returns.

Suggested change
public Writer getErrorFile() {
public Writer getErrorWriter() {

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +48
try{
Files.newByteChannel(errorFilePath.toPath(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING).close();
}
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file truncation logic creates a new ByteChannel but doesn't write anything, which means the errorFile Writer (created on line 43) may be writing to a file that gets truncated afterwards. Move the truncation logic before creating the FileWriter, or use FileWriter with append=false to handle truncation during construction.

Copilot uses AI. Check for mistakes.
public static boolean enableMod = true;


public static File errorFilePath;
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field name errorFilePath suggests it stores a path, but it's declared as File. Consider renaming to errorFile for consistency with how it's used, or change the type to Path if you want to emphasize it's a path.

Copilot uses AI. Check for mistakes.
Comment on lines 148 to 238
public static boolean logErrors(String message) {
if (LocationWebSocket.CONFIG.getErrorFile() != null) {
try {
LocationWebSocket.CONFIG.getErrorFile().write("[ERROR]: " + message + "\n");
LocationWebSocket.CONFIG.getErrorFile().flush();
LocationWebSocket.errors.remove(ERRORS.ERROR_FILE_WRITE_FAILURE);
return true;
} catch (IOException e) {
if (LocationWebSocket.errors.contains(ERRORS.ERROR_FILE_WRITE_FAILURE)) {
return false;
}
LocationWebSocket.errors.add(ERRORS.ERROR_FILE_WRITE_FAILURE);
LocationWebSocket.LOGGER.error("Failed to write to error log file", e);
return false;
}
}
return false;
}

/**
* Log errors to the error file with throwable
* @param message The error message
* @param throwable The throwable
* @return True if the error was logged, false otherwise
*/
public static boolean logErrors(String message, Throwable throwable) {
if (LocationWebSocket.CONFIG.getErrorFile() != null) {
try {
LocationWebSocket.CONFIG.getErrorFile().write("[ERROR]: " + message + " " + throwable.toString() + "\n");
LocationWebSocket.CONFIG.getErrorFile().flush();
LocationWebSocket.errors.remove(ERRORS.ERROR_FILE_WRITE_FAILURE);
return true;
} catch (IOException e) {
if (LocationWebSocket.errors.contains(ERRORS.ERROR_FILE_WRITE_FAILURE)) {
return false;
}
LocationWebSocket.errors.add(ERRORS.ERROR_FILE_WRITE_FAILURE);
LocationWebSocket.LOGGER.error("Failed to write to error log file", e);
return false;
}
}
return false;
}

/**
* Log info messages to the error file
* @param message The info message
* @return True if the info was logged, false otherwise
*/
public static boolean logInfo(String message) {
if (LocationWebSocket.CONFIG.getErrorFile() != null) {
try{
LocationWebSocket.CONFIG.getErrorFile().write("[INFO]: "+message + "\n");
LocationWebSocket.CONFIG.getErrorFile().flush();
LocationWebSocket.errors.remove(ERRORS.ERROR_FILE_WRITE_FAILURE);
return true;
} catch (IOException e) {
if (LocationWebSocket.errors.contains(ERRORS.ERROR_FILE_WRITE_FAILURE)){
return false;
}
LocationWebSocket.errors.add(ERRORS.ERROR_FILE_WRITE_FAILURE);
LocationWebSocket.LOGGER.error("Failed to write to error log file", e);
return false;
}
}
return false;
}

/**
* Log debug messages to the error file
* @param message The debug message
* @return True if the debug was logged, false otherwise
*/
public static boolean logDebug(String message) {
if (LocationWebSocket.CONFIG.getErrorFile() != null) {
try {
LocationWebSocket.CONFIG.getErrorFile().write("[DEBUG]: " + message + "\n");
LocationWebSocket.CONFIG.getErrorFile().flush();
LocationWebSocket.errors.remove(ERRORS.ERROR_FILE_WRITE_FAILURE);
return true;
} catch (IOException e) {
if (LocationWebSocket.errors.contains(ERRORS.ERROR_FILE_WRITE_FAILURE)) {
return false;
}
LocationWebSocket.errors.add(ERRORS.ERROR_FILE_WRITE_FAILURE);
LocationWebSocket.LOGGER.error("Failed to write to error log file", e);
return false;
}
}
return false;
}
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logging methods logErrors, logInfo, and logDebug have significant code duplication. Consider extracting the common logic into a private helper method like log(String level, String message) to improve maintainability.

Copilot uses AI. Check for mistakes.
Pepijn-DB and others added 4 commits December 6, 2025 22:07
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…tsMixin.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ket.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Pepijn-DB Pepijn-DB merged commit 2cd69bf into main Dec 6, 2025
3 checks passed
@Pepijn-DB Pepijn-DB deleted the fix-reseting-errors-and-logging branch December 6, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants