Comments (5)
Something is happening within the file. I had to personally edit it down to DM ID's only then paste it in by hand.
from undiscord.
I did some digging.
Essentially:
The error handling in the script is quite lackluster - instead of skipping failed messages, the entire thing just crashes.
It will fail processing the index.json when the following is true:
- The name of the chat is "null" (a lot of them)
- The messages are on a server you do not have access to anymore (which will be a lot of them)
- The messages are in a thread that has been archived (also access)
- The messages are in a channel on a server that you DO have access to but the channel has been deleted/archived/changed in a way where you lost access
Those are the main causes I could identify.
from undiscord.
Temporary Workaround
Due to limited time, I couldn’t thoroughly debug the issue and solve it more elegantly. It appears that undiscord doesn’t properly manage abandoned/deleted servers, channels, or messages. As a temporary solution, I’ve bypassed all errors, allowing the code to continue to the next message even if an error arises. Please be aware that this code should be used at your own risk. I didn’t review the entire undiscord code; I began troubleshooting from the recurring error message and attempted to catch the error before the program exited.
Modifications Made
- I modified the
runBatch
function to ensure it continues to the next message even if an error is encountered:
async runBatch(queue) {
if (this.state.running) return log.error('Already running!');
log.info(`Runnning batch with queue of ${queue.length} jobs`);
for (let i = 0; i < queue.length; i++) {
const job = queue[i];
log.info('Starting job...', `(${i + 1}/${queue.length})`);
// set options
this.options = {
...this.options, // keep current options
...job, // override with options for that job
};
try {
await this.run(true);
} catch (error) {
log.error('Error in job', `(${i + 1}/${queue.length})`, error);
}
if (!this.state.running) break;
log.info('Job ended.', `(${i + 1}/${queue.length})`);
this.resetState();
this.options.askForConfirmation = false;
this.state.running = true; // continue running
}
log.info('Batch finished.');
this.state.running = false;
}
- I removed the explicit throw. I also employed a try-catch block on !resp.ok to prevent exceptions from being thrown:
if (!resp.ok) {
// searching messages too fast
if (resp.status === 429) {
// existing error handling code...
}
// Replace only this current else block
else {
const body = await resp.text();
try {
const r = JSON.parse(body);
if (resp.status === 400 && r.code === 50083) {
// existing error handling code...
} else {
log.error(`Error deleting message, API responded with status ${resp.status}!`, r);
log.verb('Related object:', redact(JSON.stringify(message)));
this.state.failCount++;
// Instead of throwing an error, just return a failure status
return 'FAILED';
}
} catch (e) {
log.error(`Fail to parse JSON. API responded with status ${resp.status}!`, body);
// Again, instead of throwing an error, just return a failure status
return 'FAILED';
}
}
}
from undiscord.
Temporary Workaround
Due to limited time, I couldn’t thoroughly debug the issue and solve it more elegantly. It appears that undiscord doesn’t properly manage abandoned/deleted servers, channels, or messages. As a temporary solution, I’ve bypassed all errors, allowing the code to continue to the next message even if an error arises. Please be aware that this code should be used at your own risk. I didn’t review the entire undiscord code; I began troubleshooting from the recurring error message and attempted to catch the error before the program exited.
Modifications Made
1. I modified the `runBatch` function to ensure it continues to the next message even if an error is encountered:
async runBatch(queue) { if (this.state.running) return log.error('Already running!'); log.info(`Runnning batch with queue of ${queue.length} jobs`); for (let i = 0; i < queue.length; i++) { const job = queue[i]; log.info('Starting job...', `(${i + 1}/${queue.length})`); // set options this.options = { ...this.options, // keep current options ...job, // override with options for that job }; try { await this.run(true); } catch (error) { log.error('Error in job', `(${i + 1}/${queue.length})`, error); } if (!this.state.running) break; log.info('Job ended.', `(${i + 1}/${queue.length})`); this.resetState(); this.options.askForConfirmation = false; this.state.running = true; // continue running } log.info('Batch finished.'); this.state.running = false; }2. I removed the explicit throw. I also employed a try-catch block on !resp.ok to prevent exceptions from being thrown:
if (!resp.ok) { // searching messages too fast if (resp.status === 429) { // existing error handling code... } // Replace only this current else block else { const body = await resp.text(); try { const r = JSON.parse(body); if (resp.status === 400 && r.code === 50083) { // existing error handling code... } else { log.error(`Error deleting message, API responded with status ${resp.status}!`, r); log.verb('Related object:', redact(JSON.stringify(message))); this.state.failCount++; // Instead of throwing an error, just return a failure status return 'FAILED'; } } catch (e) { log.error(`Fail to parse JSON. API responded with status ${resp.status}!`, body); // Again, instead of throwing an error, just return a failure status return 'FAILED'; } } }
Did something similar to cope with the failures and just skip them. In all honesty, explicit error handling for these messages is only beneficial for logging purposes in the first place, so the user "knows" that there are some unreachable messages.
So just skipping and continuing is the way to go.
from undiscord.
@yazanzaid00 Can you send the full modified code since this isnt working for me
from undiscord.
Related Issues (20)
- Network Error HOT 3
- 400 issue when trying to delete messages with the index.json file HOT 1
- Doesnt work on Linux HOT 3
- Clicking [get] on Authorization and Author doesn't do anything. HOT 1
- Microsoft Edge does not work. HOT 2
- date range is broken
- only deletes 20-50 messages HOT 1
- Ended because API returned an empty page. HOT 8
- Error searching messages, API responded with status 400! HOT 2
- API
- Not Working, PLEASE FIX!!!!! HOT 4
- broken API HOT 2
- Stopped working entirely on chrome HOT 1
- Firefox autofills password into authorization token field, resulting in Error 401 HOT 3
- Using "@me" as the server ID causes the error 400 HOT 4
- Error deleting message, API responded with status 403! {"message":"Cannot execute action on a DM channel","code":50003} HOT 12
- No button is added in the top right corner HOT 1
- Undiscord repeatedly tries to delete messages that the user has no permission to do so. HOT 1
- Cannot delete if "int" value greater than 9999 HOT 1
- Error searching messages, API responded with status 401! HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from undiscord.