Code Monkey home page Code Monkey logo

Comments (4)

subhaze avatar subhaze commented on June 22, 2024

This is a... workaround?... if you will, but I'll trigger notifications via osascript a lot to keep my sanity on if I've coded things correctly in hooks, such as correct criteria and/or error capturing.

To capture errors, push the stderr to the stdout, then use good o'l /dev/null:

err="$(ehco 'blah' 2>&1 1>/dev/null)"
if [ -n "$err" ]; then
    osascript -e "display notification \"$err\" with title \"Hook Script Error\""
fi

The above I've typo'd echo and it'll get a notification alert that states the line number of error and command that caused it.

And if you want validation on both err and success you could else it via:

err="$(echo 'blah' 2>&1 1>/dev/null)"
if [ -n "$err" ]; then
  osascript -e "display notification \"$err\" with title \"Hook Script Error\""
else
  osascript -e "display notification \"SUCCESS! My code ain't broke!!\" with title \"Woot!\""
fi

from codekit.

bdkjones avatar bdkjones commented on June 22, 2024

Implemented for Beta 2. Here's how it works:

For Bash Hooks:

You will see messages in the Log when any of these circumstances are met:

  1. Your Hook throws an exception. Previously, CodeKit would just crash. In the future, CodeKit may still crash if your script is just so janked that the app can't recover. But for simple exceptions, such as a launch path not being accessible, you should now receive a message in the log. Note: if anyone can come up with a script that throws an exception to test this, that would be great.
  2. Your Hook returns a non-zero exit value. If your Hook does this, it is expected that you've written something to StdErr. If you have, you'll see it in the Log. If you have not, then you'll see a message in the log telling you that Hook X returned a non-zero value but didn't log anything to StdErr.
  3. Your Hook returns a zero exit code and writes anything to StdOut You'll see whatever is written to StdOut in CodeKit's log.

Note:

If it's amateur hour and you return 0 but write output to StdErr (here's looking at you, TypeScript!), that won't be logged. Likewise, if you return non-zero but write to StdOut, that won't be logged either. Program correctly. The error level of the logged message will be regular (green) for StdOut messages and error (red) for StdErr messages.

For AppleScript Hooks:

There is a new API in the scripting dictionary for Beta 2. You can use this to log any message with any error level (regular, warning, or "problem" --- because error is a reserved word in AppleScript).

from codekit.

bdkjones avatar bdkjones commented on June 22, 2024

I should also mention an important implementation detail. Suppose you highlight 5 files in CodeKit and click Process All. Each of these files meets the criteria to trigger a given Hook.

The way CodeKit works, all five of these files will be processed using the settings you've specified in the app (syntax check, transpile, minify, etc.) BEFORE any Hooks are run. That is, the Hook is run at the end of the group of files being processed, not after each individual file is processed.

When the build process is complete, this will still apply. During a build, files will be "grouped" based on their dependencies. If File X imports the output of File A, then A will compile in one "flight" or "group" and then when that group is finished, X will compile in a second group. Hooks will be run at the end of each "flight" or group.

This is basically for performance reasons.

from codekit.

subhaze avatar subhaze commented on June 22, 2024

Nice! I'll try to give this a go on next release! Great addition.

from codekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.