Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: pkg/code_transformers/lib/src/messages.dart

Issue 513023002: Step one towards stable error messages with details: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Contains all warning messages produced by the code_transformers package.
6 library code_transformers.src.messages;
7
8 import 'package:code_transformers/messages/messages.dart';
9
10 const noAbsolutePaths = const MessageTemplate(
jakemac 2014/09/03 17:20:41 These should really be all caps names since they a
Siggi Cherem (dart-lang) 2014/09/04 02:32:13 :) I think there is not consensus on that part of
jakemac 2014/09/04 14:42:37 Weird, but ok :). To me all caps constants is the
11 const MessageId('code_transformers', 1),
12 'absolute paths not allowed: "%-url-%"',
13 'Absolute paths not allowed',
14 '''
15 The transformers processing your code were trying to resolve a URL and identify
16 a file that they correspond to. Currently only relative paths can be resolved.
17 ''');
18
19 const invalidUrlToOtherPackage = const MessageTemplate(
20 const MessageId('code_transformers', 2),
21 'Invalid url to reach to another package: %-url-%. Path '
Kathy Walrath 2014/09/03 18:56:36 Global change to text: url -> URL
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 Done.
22 'reaching to other packages must first reach up all the '
23 'way to the %-prefix-% folder. For example, try changing the url above '
Kathy Walrath 2014/09/03 18:56:35 is it clear what "above" means?
Kathy Walrath 2014/09/03 18:56:36 Be consistent about using folder vs. directory. I
Siggi Cherem (dart-lang) 2014/09/04 02:32:13 Done.
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 It seems we didn't need it :). removed
24 'to: %-fixedUrl-%',
25 'Invalid url to reach another package',
26 '''
27 To reach an asset that belongs to another package, we use `package:` URLs in
Kathy Walrath 2014/09/03 18:56:35 we use -> use In general, avoid "we" in messages.
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 Done.
28 Dart code, but in any other language (like HTML or CSS) we use relative URLs.
Kathy Walrath 2014/09/03 18:56:36 we use -> use
Siggi Cherem (dart-lang) 2014/09/04 02:32:13 Done.
29
30 These are the rules you must follow to write URLs that refer to files in other
Kathy Walrath 2014/09/03 18:56:35 -> Follow these rules when writing... This is way
Siggi Cherem (dart-lang) 2014/09/04 02:32:13 I was debating about this - one idea I was thinkin
31 packages:
32
33 * if the file containing the relative URL is an entrypoint under `web`, use
Kathy Walrath 2014/09/03 18:56:36 if -> If
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 Done.
34 `packages/package_name/path_to_file`
35
36 * if the file containing the URL is under `web`, but on a different directory
Kathy Walrath 2014/09/03 18:56:35 if -> If on -> in
Siggi Cherem (dart-lang) 2014/09/04 02:32:13 Done.
37 than your entrypoint, walk out to the same level as the entrypoint first,
38 then enter the `packages` folder.
39
40 **Note**: this means that if you have two entrypoints including this file,
Kathy Walrath 2014/09/03 18:56:36 this means that if you have two entrypoints includ
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 Done.
41 either both entrypoints have to live in the same directory, or you need to
42 move the file to the `lib` folder.
43
44 * if the file containing the URL lives under `lib`, walk up as many levels as
Kathy Walrath 2014/09/03 18:56:36 if -> If
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 Done.
45 directories you have + 1. This is because code in `lib/a/b` is loaded from
46 `packages/package_name/a/b`.
47
48 The rules are easier to follow if you know how the code is layed out for
Kathy Walrath 2014/09/03 18:56:35 layed -> laid (global)
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 <facepalm> thx!
Kathy Walrath 2014/09/04 17:07:28 I had to look it up to be sure. :)
49 Dartium before you build, and how it is layed out after you build it with `pub
50 build`. Consider the following example:
51
52 package a
53 lib/
54 '- a1.html
Kathy Walrath 2014/09/03 18:56:35 Could you use | instead of '? You used | below (fo
Siggi Cherem (dart-lang) 2014/09/04 02:32:13 Sure, I was basically using the style that pub use
55
56 web/
57 '- a2.html
58
59 package b
60 lib/
61 |- b1.html
62 '- b2/
63 '- b3.html
64
65 package c
66 lib/
67 '- c3.html
68
69 web/
70 |- index.html
71 |- index.dart
72 |- c1/
73 '- c2.html
74
75 If your app is package `c`, you'll notice that in your file system there is a
Kathy Walrath 2014/09/03 18:56:36 you'll notice that in your file system there is a
Siggi Cherem (dart-lang) 2014/09/04 02:32:13 Done.
76 packages folder generated in the web folder, like this:
77
78 web/
79 |- index.html
80 |- index.dart
81 |- c1/
82 | '- c2.html
83 '- packages/
84 |- a/
85 | '- a1.html
86 |- b/
87 | |- b1.html
88 | '- b2/
89 | '- b3.html
90 '- c/
91 '- c3.html
92
93 Note that there is no `lib` folder under the `packages` folder. When you load
94 `index.html` in Dartium, it will infer that the package root is under
Kathy Walrath 2014/09/03 18:56:35 what is "it"? Also, avoid "there is" when possible
Siggi Cherem (dart-lang) 2014/09/04 02:32:13 Good points. Thanks - here is what I ended up with
95 `web/packages/`.
96
97 If you need to refer to any file in other packages from `index.html`, you can
98 simply do `packages/package_name/path_to_file`. For example
99 `packages/b/b2/b3.html`. From `index.html` you can also refer to files under the
100 web folder of the same package using a simple relative URL, like `c1/c2.html`.
101
102 However, if you want to load `a1.html` from `c2.html`, you need to reach out to
103 the packages folder that lives next to your entrypoint and then load the file
104 from there, for example `../packages/a/a1.html`. Because pub generates symlinks
105 to the packages folder also under c1, you may be tempted to write
106 `packages/a/a1.html`, but that is incorrect - it would yield a canonicalization
107 error (see more below).
108
109 If you want to load a file from the lib folder of your own package, you
110 should also use a package URL. For example, `packages/c/c3.html` and not
111 `../lib/c3.html`. This will allow you to write code in `lib` in a way that it
112 can be used within and outside your package without making any changes to it.
113
114 Because any time you reach inside a `lib/` folder you do so using a `packages/`
115 URL, the rules for reaching into other files in other packages are always
116 consistent: go up to exit the `packages` folder and go back inside to the file y ou
117 are looking for. For example, to reach `a1.html` from `b3.html` you need to
118 write `../../../packages/a/a1.html`.
119
120 The motivation behind all these rules is that we would like to have URLs that
121 work under many scenarios at once:
122
123 * They need to work in Dartium without any code transformation: resolving the
124 path in the context of a simple HTTP server, or using `file:///` URLs,
125 should yield a valid path to assets. Since pub already creates a `packages`
126 directory next to entrypoints of your application, we assume we can use it.
127
128 * They need to be canonical. To take advantage of caching, multiple URLs
129 reaching the same asset should resolve to the same absolute URL.
130
131 Also, in projects that use HTML imports (like polymer) we make sure that if
132 you reach a library twice, once with Dart imports, and a second time with
133 HTML imports, then they are correctly resolved to be the same library. Our
134 rules are designed to allow tools to ensure this.
135
136 For example, consider you have an import might like:
137
138 <link rel=import href=packages/a/a.html>
139
140 where a.html has `<script type="application/dart" src="a.dart">`. If your
141 Dart entrypoint also loads `"package:a/a.dart"`, then we need to make sure
142 that both versions of `a.dart` are loaded from the same URL. Otherwise, you
143 may see errors at runtime like: `A is not a subtype of A`, which can be
144 extremely confusing.
145
146 When you follow the rules above, our tools can detect the pattern in the
147 HTML-import URL containing `packages/` and canonicalize the import
148 by converting `packages/a/a.dart` into `package:a/a.dart` under the hood.
149
150 * They need to continue to be valid after applications are built.
151 Technically this could be done automatically with pub transformers, but to
152 make sure that code works also in Dartium with a simple HTTP Server,
153 existing transformers do not fix URLs, they just detect inconsistencies and
154 produce an error message like this one, instead.
Kathy Walrath 2014/09/03 18:56:36 This is a lot of doc! How about I put it in a page
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 That's actually how it works, I'm just storing the
Kathy Walrath 2014/09/04 17:07:27 What I meant was I didn't want to bury this doc (a
155 ''');
156
157 const incompletePrefixPath = const MessageTemplate(
158 const MessageId('code_transformers', 3),
159 'incomplete %-prefix-%/ path. It should have at least 3 '
160 'segments %-prefix-%/name/path_from_name\'s_%-folder-%_dir',
161 'Incomplete import to asset in another package',
Kathy Walrath 2014/09/03 18:56:36 to -> of?
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 rephrased, I should not use the word import here a
162 '''
163 Currently we require that URLs that refer to assets in other packages to
164 explicitly mention the `packages/` folder. In the future we might remove this
165 requiremnt, but for now we ask that you use a canonical URL form for it.
Kathy Walrath 2014/09/03 18:56:36 requiremnt -> requirement
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 Done.
166
167 For example, if you have `packages/a/a.html` using an HTML import to
168 `packages/b/b.html`, you could technically just write `../b/b.html`, but we
Kathy Walrath 2014/09/03 18:56:35 who is "we" really? polymer.dart? The polymer tran
Siggi Cherem (dart-lang) 2014/09/04 02:32:14 Done. also removed `we` elsewhere...
169 require that you write `../../packages/b/b.html`.
170 See [issue 15797](http://dartbug.com/15797).
171 ''');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698