summary refs log tree commit diff stats
path: root/scripts
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-07 16:55:33 +0200
committerhut <hut@lavabit.com>2011-10-07 16:55:33 +0200
commit13549f1e53c7342f040b20a3f3075778b1d3302b (patch)
tree7f7a333b5785056ea2e33fb52cda96a5da3d2074 /scripts
parent6a3b4bca95d9341ac2a593c5935d463bb9d5e0cf (diff)
downloadranger-13549f1e53c7342f040b20a3f3075778b1d3302b.tar.gz
widgets.browserview: Try to fix crash
When running ranger with two directories and using a command with macros, this
crash happens.  To reproduce, run this and then type "yp"

ranger /usr/bin /var/tmp

Traceback was:

Ranger version: 1.5.0, executed with python 3.2.2
Locale: en_US.UTF-8
Current file: /usr/lib
Traceback (most recent call last):
  File "/home/common/archive/repos/ranger/ranger/core/main.py", line 103, in main
    fm.loop()
  File "/home/common/archive/repos/ranger/ranger/core/fm.py", line 202, in loop
    ui.handle_input()
  File "/home/common/archive/repos/ranger/ranger/gui/ui.py", line 210, in handle_input
    self.handle_key(key)
  File "/home/common/archive/repos/ranger/ranger/gui/ui.py", line 146, in handle_key
    self.press(key)
  File "/home/common/archive/repos/ranger/ranger/gui/ui.py", line 161, in press
    quantifier=keybuffer.quantifier)
  File "/home/common/archive/repos/ranger/ranger/core/actions.py", line 111, in execute_console
    string = self.substitute_macros(string, additional=macros)
  File "/home/common/archive/repos/ranger/ranger/core/actions.py", line 115, in substitute_macros
    return _MacroTemplate(string).safe_substitute(self._get_macros(),
  File "/home/common/archive/repos/ranger/ranger/core/actions.py", line 153, in _get_macros
    macros[i + 'f'] = shell_quote(tab_dir.pointed_obj.path)
AttributeError: 'NoneType' object has no attribute 'path'
Diffstat (limited to 'scripts')
0 files changed, 0 insertions, 0 deletions
='#n38'>38 39 40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63


                                                                             




































                                                                                                                         
                                               








                                                             
                                                                                                                                                                 











                                                                          
//: Let's raise errors when students use real hardware in any recipes besides
//: 'main'. Part of the goal is to teach them testing hygiene and dependency
//: injection.
//:
//: This is easy to sidestep, it's for feedback rather than safety.

:(before "End Globals")
vector<type_tree*> Real_hardware_types;
:(before "Begin transform_all")
setup_real_hardware_types();
:(before "End transform_all")
teardown_real_hardware_types();
:(code)
void setup_real_hardware_types() {
  Real_hardware_types.push_back(parse_type("address:screen"));
  Real_hardware_types.push_back(parse_type("address:console"));
  Real_hardware_types.push_back(parse_type("address:resources"));
}
type_tree* parse_type(string s) {
  reagent x("x:"+s);
  type_tree* result = x.type;
  x.type = NULL;  // don't deallocate on return
  return result;
}
void teardown_real_hardware_types() {
  for (int i = 0;  i < SIZE(Real_hardware_types);  ++i)
    delete Real_hardware_types.at(i);
  Real_hardware_types.clear();
}

:(before "End Checks")
Transform.push_back(check_for_misuse_of_real_hardware);
:(code)
void check_for_misuse_of_real_hardware(const recipe_ordinal r) {
  const recipe& caller = get(Recipe, r);
  if (caller.name == "main") return;
  if (starts_with(caller.name, "scenario_")) return;
  trace(9991, "transform") << "--- check if recipe " << caller.name << " has any dependency-injection mistakes" << end();
  for (int index = 0;  index < SIZE(caller.steps);  ++index) {
    const instruction& inst = caller.steps.at(index);
    if (is_primitive(inst.operation)) continue;
    for (int i = 0;  i < SIZE(inst.ingredients);  ++i) {
      const reagent& ing = inst.ingredients.at(i);
      if (!is_literal(ing) || ing.name != "0") continue;
      const recipe& callee = get(Recipe, inst.operation);
      if (!callee.has_header) continue;
      if (i >= SIZE(callee.ingredients)) continue;
      const reagent& expected_ing = callee.ingredients.at(i);
      for (int j = 0;  j < SIZE(Real_hardware_types);  ++j) {
        if (*Real_hardware_types.at(j) == *expected_ing.type)
          raise << maybe(caller.name) << "'" << to_original_string(inst) << "': only 'main' can pass 0 into a " << to_string(expected_ing.type) << '\n' << end();
      }
    }
  }
}

:(scenarios transform)
:(scenario warn_on_using_real_screen_directly_in_non_main_recipe)
% Hide_errors = true;
def foo [
  print 0, 34
]
+error: foo: 'print 0, 34': only 'main' can pass 0 into a (address screen)