Commit 2849a87
committed
Improve pack generator robustness and error handling
Based on code review feedback, this commit addresses several critical issues:
1. **Better Bundler context detection**: Now checks ENV['BUNDLE_GEMFILE']
for more robust detection of meaningful Bundler contexts
2. **Enhanced Rails availability checking**: Safely verifies Rails.application
can actually load tasks, with proper error handling
3. **Consistent error handling**: Errors are always written to stderr,
even in silent mode. Backtrace included when DEBUG env var is set
4. **Reduced code complexity**: Refactored run_rake_task_directly into
smaller, focused methods (load_rake_tasks, prepare_rake_task,
capture_output, handle_rake_error) to satisfy RuboCop complexity checks
5. **Maintained test compatibility**: Tests continue to pass because the
code properly falls back to bundle exec in test environment where
BUNDLE_GEMFILE is not set
These changes ensure:
- Tests work correctly (they mock system calls which are used in test env)
- Production bin/dev usage is optimized (direct Rake execution when safe)
- Error messages are never silently swallowed
- More robust detection of execution context1 parent c2803fb commit 2849a87
1 file changed
+57
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
42 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
43 | 57 | | |
44 | 58 | | |
45 | 59 | | |
46 | 60 | | |
47 | 61 | | |
48 | | - | |
49 | | - | |
| 62 | + | |
| 63 | + | |
50 | 64 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
56 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
57 | 94 | | |
58 | 95 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 96 | + | |
66 | 97 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 98 | + | |
| 99 | + | |
71 | 100 | | |
72 | 101 | | |
73 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
74 | 111 | | |
75 | 112 | | |
76 | 113 | | |
| |||
0 commit comments