Getting stdin for formatters, and replacing text

Here’s the source script and the output from the command line:

   λ ~ : cat ~/tmp/t.pl
#!/usr/bin/perl -w

use strict; use warnings; sub something{return;} my $whatever = something();

   λ ~ : ~/bin/perltidy.sh < ~/tmp/t.pl
#!/usr/bin/perl -w

use strict;
use warnings;
sub something { return; }
my $whatever = something();

So I should see the change, given what’s on stdout, right?

I assume command-line formatters should send to stdout and not write to the file directly.

Right, that’s what it is doing for me. Let me test on OSX, maybe something is broken there.

Nope, works fine on OSX also for me.

All I’m doing:

1 - Create new file perltidy.sh with the following contents:

#!/bin/sh
perltidy -bvt=0 -pt=0 -bl -bt=0 -t -nola -i=1 -q <&0 -st

2 - chmod +x the file
3 - Add the formatter in Komodo, the only fields I set are the name, language (Perl) and executable.
4 - create a blank file and set the language to perl
5 - paste in your perl snippet
6 - invoke the formatter

Works for me when I take those steps. Anything you’re doing differently?

Close. My perltidy.sh is in post #7, above, and you have my test case as it. Otherwise, I think that’s all correct.

Ok, try this:

Use your regular profile (not safe-mode), restart Komodo (so the log is reset) and execute the following in the console widget (bottom pane):

ko.logging.getLogger('koGenericFormatter').setLevel(10)

Then try to run your formatter again. Once that fails copy Help > Troubleshooting > View Log File into this thread.

You may also be able to get more debugging information with the following snippet (use the console again). Note this snippet assumes the formatter we’re debugging is the last one that was added:

var formatterSvc = Components.classes["@activestate.com/koFormatterService;1"].getService(Components.interfaces.koIFormatterService);
var context = formatterSvc.createFormatterContextFromView(ko.views.manager.currentView);
var formatter = ko.formatters.getAllFormatterConfigurationsForPrefset(ko.prefs).slice(-1)[0];
formatter = formatterSvc.getFormatterWithName(formatter.getStringPref("formatter_name"));
formatter.format(context);

pystderr.log is empty after trying my formatter. So that’s cool.

The latter snippet shows this in the console when I execute it:

Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [koIFormatter.format]
Stack Trace:

    @chrome://console/content/js/console.js line 149 > eval:5:0
    this.execute@chrome://console/content/js/console.js:149:25
    this.onKeyNav/<@chrome://console/content/js/console.js:113:24

Did you use your regular profile (not safe-mode)?

It’s impossible that the error log is completely emtpy. Please try to navigate to it manually:

http://docs.komodoide.com/Troubleshooting/Where-does-Komodo-keep-settings-data

Tried it again. This time I get:

[2016-05-21 10:00:05,598] [WARNING] console-logger: Error in parsing value for 'left'.  Declaration dropped. (1) in chrome://console/content/views/console.html:0
ERROR:xpcom:Unhandled exception calling 'G     int8 * formatter_prefset(out retval nsISomething);'
Traceback (most recent call last):
  File "/Applications/Komodo IDE 10.app/Contents/Resources/python/xpcom/server/policy.py", line 274, in _CallMethod_
    ret = getattr(self._obj_, name) # Let attribute error go here!
AttributeError: 'koFormatterScimozContext' object has no attribute 'formatter_prefset'
ERROR:xpcom:Unhandled exception calling 'int8 * format(in nsISomething);'
Traceback (most recent call last):
  File "/Applications/Komodo IDE 10.app/Contents/Resources/python/xpcom/server/policy.py", line 300, in _CallMethod_
    return 0, func(*params)
  File "/Applications/Komodo IDE 10.app/Contents/Resources/components/koGenericFormatter.py", line 51, in format
    if context.formatter_prefset.hasPref(self._prefName):
  File "/Applications/Komodo IDE 10.app/Contents/Resources/python/xpcom/client/__init__.py", line 396, in __getattr__
    return getattr(interface, attr)
  File "/Applications/Komodo IDE 10.app/Contents/Resources/python/xpcom/client/__init__.py", line 494, in __getattr__
    return NS_InvokeByIndex(self._comobj_, method_index, args)
Exception: 2147500037 (NS_ERROR_FAILURE)

that’s when I enable the second debug string. When I use the first one, I get:

[2016-05-21 10:01:19,793] [DEBUG] koGenericFormatter: command: u'"/Users/greggthomason/bin/perltidy.sh"'

I am using my regular profile. This is a new profile on a new machine, so I don’t think it could be migration cruft related.

Could you share the full error log?

Could you share your prefs.xml? You can send it to support@activestate.com and include a reference to this topic.