mirror of
https://github.com/jehna/humanify.git
synced 2026-05-06 05:40:27 +03:00
[GH-ISSUE #111] Error: Failed to stringify code #40
Labels
No labels
bug
enhancement
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/humanify#40
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Yusufkulcu on GitHub (Sep 21, 2024).
Original GitHub issue: https://github.com/jehna/humanify/issues/111
I trade using chatgpt. I am getting the error shown in the screenshot. The file size is large (7mb on average) and the number of lines is high (134881 lines). What is the problem? Can you help me? This is very important to me
@Yusufkulcu commented on GitHub (Sep 22, 2024):
@jehna please help me
@jehna commented on GitHub (Sep 22, 2024):
Can you run humanify using
--verboseflag and post the output? It gives a lot more debug data to work with@Yusufkulcu commented on GitHub (Sep 22, 2024):
I'm trying right now
@Yusufkulcu commented on GitHub (Sep 22, 2024):
@jehna
@Yusufkulcu commented on GitHub (Sep 22, 2024):
@jehna
Do you have any suggestions on what I can do to fix the problem?
@jehna commented on GitHub (Sep 22, 2024):
Hmm. Seems like an issue with some of the dependencies, at least that error does not originate from humanify's code.
In hindsight it seems that using pkgroll was a bad idea, as it seems to mess with the dependencies' stack traces.
I think this would need some extra debugging to solve.
@Yusufkulcu commented on GitHub (Sep 22, 2024):
@jehna
So what can I do as a solution? Solving this code is very important to me
@Yusufkulcu commented on GitHub (Sep 22, 2024):
How can I send you error details
@jehna commented on GitHub (Sep 22, 2024):
Whoops, closed this by accident. You could check which part of the bundle throws the error, that would help
@Yusufkulcu commented on GitHub (Sep 22, 2024):
@jehna
When I check, the "transformFromAstAsync" function in the "@babel/core" package gives an error. Since I'm not familiar with the package, I have no idea how to fix the problem. I would be grateful if you could help
@Yusufkulcu commented on GitHub (Sep 22, 2024):
@jehna
Please help me
@Yusufkulcu commented on GitHub (Sep 22, 2024):
@jehna
Will you help?
@jehna commented on GitHub (Sep 22, 2024):
@Yusufkulcu thanks for the additional info, but unfortunately I'm not able to respond to bigger work immediately (not being paid for doing ppen source etc)
@jehna commented on GitHub (Sep 22, 2024):
I think I'll be able to investigate more within a few weeks when I have some time
@Yusufkulcu commented on GitHub (Sep 22, 2024):
I understood. I would be very happy if I know when the study is concluded. We hope that it will be concluded as soon as possibleI understood. I would be very happy if I know when the study is concluded. Hoping to conclude it as soon as possible 😊
@0xdevalias commented on GitHub (Sep 25, 2024):
@Yusufkulcu I haven't looked too deeply into this, but I suspect the issue is likely not going to be directly within
transformFromAstAsyncwithin@babel/core; but more with how it is being used by eitherhumanify's AST parsing code, or how thewebcrackproject it depends on is using it.Looking up that
"Failed to stringify code"error leads to this source withinhumanify:github.com/jehna/humanify@2ac5d25d1d/src/plugins/local-llm-rename/visit-all-identifiers.ts (L57-L62)It looks like it throws that when the result from
transformFromAstAsynchas a falsy value forstringified?.codeDepending on your skill at debugging, it might be useful to see what the value of
astbeing passed in is, as well as the full value ofstringifiedthat is being returned.Depending on the sensitivity of the code you're running this on, it could also be useful if you're able to attach the code that consistently triggers this area; even better if you're first able to reduce it to a minimal example that triggers the error; as that would make it a lot easier for others to help debug/understand what might be causing it.
@Yusufkulcu commented on GitHub (Sep 25, 2024):
I didn't understand exactly what I was supposed to do:(
@0xdevalias commented on GitHub (Sep 25, 2024):
@Yusufkulcu At a minimum, if you are able to attach the code you're trying to decrypt, that would be really useful to help narrow things down.
@Yusufkulcu commented on GitHub (Sep 25, 2024):
Yes, you are right, I have attached the file below. Github I uploaded it to my Google drive account because it doesn't allow javascript file uploading.
https://drive.google.com/file/d/1H9_g6L32xMchrpi-dIRksz7MyQkmWm2a/view?usp=drivesdk
@jehna
@0xdevalias
@0xdevalias commented on GitHub (Sep 25, 2024):
@Yusufkulcu Thanks. If you just rename the .js file to .txt that would usually let you upload it directly to GitHub as well.
@Yusufkulcu commented on GitHub (Sep 25, 2024):
Thanks for the info. I reloaded it as txt. I will be waiting for your help. It's an important project for me
main.txt
@0xdevalias commented on GitHub (Sep 26, 2024):
@Yusufkulcu Thanks for that. I ran it through the web version of
and it seemed to unpack correctly there, which makes it a higher likelihood that the issue is withinhumanify`:Depending on your use case, I wonder if you might be able to use that unpacked/unmangled version as a starting point for your analysis; even though it doesn't have the 'nice variable renames' that
humanifyadds on top? You might also be able to runhumanifyagainst individual files from that extracted version in the interim as well.@0xdevalias commented on GitHub (Sep 26, 2024):
@Yusufkulcu Looking at your screenshot from https://github.com/jehna/humanify/issues/111#issuecomment-2365764329, it looks like the error is occuring on file 18:
Looking at the code where this happens, it seems to be within
unminify, just afterwebcrackhas run to extract the files, and in the main loop where those files are being processed:github.com/jehna/humanify@c2e0be679d/src/unminify.ts (L6-L30)Since even with
--verboseenabled,humanifydoesn't output the filenames it's processing, it makes it a bit harder to debug; but running it through a debugger we can see what 'file 18' ofextractedFilescorresponds with anyway (assumingwebcrackconsistently unpacks the code the same way); which since the output log showsi + 1, that makes it actually entry 17 in the array (because it's 0-indexed); which seems to be the extracted file1.js:Looking at the contents of
output/1.js, we can see that it's an empty file:As part of the main
unminifyloop, the code then callsplugins.reduceon thepluginspassed in tounminify:github.com/jehna/humanify@c2e0be679d/src/commands/openai.ts (L26-L30)When run as
humanify openai, these plugins are:babel(Ref)openaiRename({ apiKey, model: opts.model })(Ref)prettier(Ref)The
Failed to stringify codeerror you're seeing comes from thevisitAllIdentifiersfunction, just after callingbabel'stransformFromAstAsync:github.com/jehna/humanify@c2e0be679d/src/plugins/local-llm-rename/visit-all-identifiers.ts (L57-L61)Which is called by the
openaiRenameplugin that is passed tounminify:github.com/jehna/humanify@c2e0be679d/src/plugins/openai/openai-rename.ts (L6-L38)transformFromAstAsyncaccepts a parsedast, and returns an object withcode,map, andast.Presumably, with an empty file as input, that would result in an empty ast, which when passed to
transformFromAstAsync, would result in an empty string returned in thecodefield.Given the check that ends up throwing the error you're seeing is looking for a falsy value in
stringified.code; the empty string would definitely trigger that:github.com/jehna/humanify@c2e0be679d/src/plugins/local-llm-rename/visit-all-identifiers.ts (L57-L62)@Yusufkulcu @jehna So the above seems to be the debugging as to the 'why' of what is going on; though I'm not familiar enough with the codebase to suggest where the best point of implementing the fix is.
If I was to suggest the most minimal/localised fix, it would be to the
if (!stringified?.code)check withinvisitAllIdentifiers(Ref)Though an argument could also be made that filtering out empty/similar files at the
unminifylevel could have it's merits (Ref); though that would then make it less generic/flexible, as theoretically a plugin in the chain could make it a non-empty file before theopenaiRenameactually needs to process it.So I still think the best fix is probably within
visitAllIdentifiers.In fact, in looking through related issues, this just seems to be a variation of the same root cause that I raised in this issue:
I also think the general CLI output should be improved to explain what is happening better. eg. a message before running
webcrack, outputting the actual filenames (not just the file number), etc.These issues also seem to tangentially relate to some aspect of this latter suggestion:
@Yusufkulcu commented on GitHub (Sep 26, 2024):
Thanks for the suggested solution. It works largely without "beautifying variable" values. But my goal is to change it completely. It seems to take a long time to decode the files in the "outputs" folder one by one with Humanify. Is there a shortcut to this?
@0xdevalias commented on GitHub (Sep 26, 2024):
@Yusufkulcu Do you mean that the process takes a long time in general? Or that having to manually run it against each file takes a long time?
If the latter, you could probably extract them with
webcrack, then write a bash script/similar that runshumanifyon each of those files individually. I'm not 100% sure how the renames works across module boundaries/for exports/similar.. but I think it already reads/parses each of the split files individually anyway, so I don't think it would be much worse to run it this way..Actually.. it will probably still be a bit slower because of the startup boilerplate, and then trying to run
webcrackagainst the file each time (even though they are already split)..While it's not currently a feature, if you're going to need to be re-running the variable renaming process on future versions of the same code, this feature request would probably also be relevant to you:
@jehna It might be a neat/useful feature to be able to run
humanifyagainst a source file (or multiple files/directory of files/etc) while bypassing thewebcrackstep; that way it could be used on files that had already been unpacked/etc withwebcrack(or another tool likewakaru) previously.Edit: I split this last part into its own issue:
@Yusufkulcu commented on GitHub (Sep 26, 2024):
Thank you for your detailed explanation. I'm going to try the parsed source code separately by writing a script that implements the humanify command. I have one more question.
What is the reason why the "Webcrack" package breaks the code into pieces. I divide it into many files in the Outputs folder and I don't know what they are. I wonder if you can explain that. Thank you in advance
@0xdevalias commented on GitHub (Sep 26, 2024):
@Yusufkulcu It might actually be quicker for you to just clone the
humanifyrepo and temporarily patch the code to skip trying to run against empty files.I haven't tried it, but a quick/dirty hack fix could just be to add an
ifcheck to skip empty files withinunminify:Something like:
While this wouldn't really be suited for a proper fix, it should hopefully be enough to do what you need to work around this bug in the meantime.
@Yusufkulcu The original source file you provided is a webpack bundle of code (or similar), where the original many code files have been combined into a single file. When
webcrackruns on it, it 'undoes' this bundling, and so splits the single file back into many files similar to how it was originally.@Yusufkulcu commented on GitHub (Sep 27, 2024):
Thanks for the suggestion, it doesn't give that error anymore, but now I'm getting another error. I get the following error in file 63. I've added the original file and the file where I got the error below. It's a pretty long mistake, so I added some more pictures.
6blF.txt
main.txt
@0xdevalias commented on GitHub (Sep 27, 2024):
@Yusufkulcu I'm glad that workaround helped get around the first issue :)
That new error you're running into seems to now be the same/similar to the errors being discussed in this issue:
You might like to try the potential solution I described in this comment, RE: cloning the
humanifyrepo and bumping thewebcrackversion inpackage.jsonto the latest version (2.14.1):@0xdevalias commented on GitHub (Sep 29, 2024):
For context/continuity, @j4k0xb has raised 2 bugfix PR's for the bugs identified in this issue: