GS_04_Try_to_break_things - XLRIT/gears GitHub Wiki
In this part of the getting started we are going to make you break things and cause some errors. You will learn about them and how to solve them:
1. Table of content
- 1. Table of content
- 2. Get a build error
- 3. Incorrect indents
- 4. Incorrect sentence names
- 5. Incorrect or missing names
- 6. Required field is not filled
- 7. Type mismatches
- 8. Conclusion
2. Get a build error
Getting a build error does not happen that often. If it does you have good reason to send a bug to XLRIT so they can fix it. As an insider I know that version 1.6.6 still has a bug that will cause a compilation error. Let's trigger it:
- In the file
Order products.sn
change the following line:
results in:
"customer has ordered a product"
to this:
results in:
"customer has ordered a product"
and
"customer has ordered a product"
- Do a GEARS:Generate and a GEARS:Show Diagrams (remember, press CTRL+SHIFT+B first)
Although so far all seems fine, this will be a problem in this version of GEARS. This is because exactly the same result is produced twice. When this issue is fixed this will of course not be a problem, but in the current version it is and it will become apparent if we try to build it.
- Do a GEARS:Build. As you can see this causes Build errors.
Time to send an email to [email protected] because in most cases this is something the XLRIT needs to fix. To continue you could work around this issue but that may require some creativity from your end which I hope you will have after you have completed this getting started.
3. Incorrect indents
As you know by now indents are important for GEARS. And they should be for you as well because they make your work look good and easy to read. Now GEARS forces you to use proper indents, and gives an error if you do not. Let's trigger such an error.
- In the file
Order products.sn
change the following line:
results in:
"customer has ordered a product"
and
"customer has ordered a product"
to this:
results in:
"customer has ordered a product"
and
"customer has ordered a product"
Did you notice the the extra space in the beginning of the last line? There is the incorrect (extra) indent.
- Do a GEARS:Generate. It should result in an error, this time a correct error that you can fix:
- in parser: 1 problem
- Error in parser: end of input expected
Order product.sn:5:5: and
The parser is the part of the GEARS generator that reads the .sn files. Parser errors are also not alway too easy to understand. The reason for that it that the parser stops analysing the error the moment it finds the first error. It does not take a look at the other lines in the file to find out what is wrong. Parsers are fast, but not very intelligent.
In this example the parser stops at line 5 and says "I found an and
but that cannot be right because next line cannot be part of this results in:
because it has a different indent and must therefore be part of something else".
4. Incorrect sentence names
- In the file
Order products.sn
change the following line:
results in:
"customer has ordered a product"
and
"customer has ordered a product"
to this:
results in:
"customer has ordered product"
Did you notice that the title of this definition is slightly different? It is missing the a
befor product"
.
- Do a GEARS:Generate. It should result in this error:
- in process 'Order product': 1 problem
- Error in process 'Order product': sentence "customer has ordered product" not found
Order product.sn:4:5: "customer has ordered product"
This means that GEARS has not found a matching sentence definition. You can fix this things easily by making them match.
- Make them match now and do a GEARS:Generate again to see if you fixed it.
VS Code even has the option to prevent this from happening. For instance by selecting a sentence and then press CTRL+F2. At that moment all occurences of that same text are selected and you start typing to change it. It will change on all of those selected occurences. Sadly this does not work if the sentence is in another file. In newer versions of the GEARS extension we will try to make it even more easy to change all sorts of titles and names across all files in a project.
5. Incorrect or missing names
- In the file
Order products.sn
change the following line:
quantity = 1
to this:
quantiti = 1
Pretty clear right. This is changing the name of an attribute of an entity to something that is not defined in the LDM.
- Do a GEARS:Generate. It should result in this error:
- in process 'Order product': 1 problem
- Error in process 'Order product': type ORDER has no attribute 'quantiti'
Order product.sn:9:7: quantiti = 1
^
This could either be a simply typo, but it could also simply mean that you intended change the name of this attribute and you simply forgot to change it in the LDM.sn
as well, or you even wanted to start using a completly new attribute, but forgot to add it to the LDM.sn
. Of course this case it was a simple typo.
- Fix that typo and do a GEARS:Generate again to so if you solved it.
6. Required field is not filled
- In the file
Order products.sn
remove the following line:
quantity = 1
- Do a GEARS:Generate. It should result in this error:
- in process 'Order product': 1 problem
- Error in process 'Order product': The following required attributes have not been set for ORDER in ORDERS:
quantity
Order product.sn:7:5: one ORDER in ORDERS is created with:
^
All fields in the LDM are considered required by default and you have to explicitly mark them as optional if you want the ability to leave them empty. So you could solve this by restoring that line again, but you can also mark that attribute as optional in the LDM.sn
. Lets do that:
- In the file
LDM.sn
change the following line:
quantity : number
to
quantity : number optional
- Do a GEARS:Generate again.
The issue is solved. However, you should really think about if it is a good idea that you do not have the number of products that you want to order. Choosing if an attribute is optional should always be a concious decision. When you do more developing, you will figure out the pro's and cons, but for now, the rule of thumb is "If it is not really really needed to be optional, then keep it required.
By the way:
input from
is also required by default. Even if the attribute itself is optional. To make aninput from
optional itself, simply change it tooptional input from
.
- Because we want quantity to be required, simply undo the changes you made in this section.
7. Type mismatches
- In the file
Order products.sn
change the following line:
quantity = 1
to this:
quantity = 'some text value'
- Do a GEARS:Generate. It should result in this error:
- in process 'Order product': 1 problem
- Error in process 'Order product': cannot assign a value of type text to an attribute of type integer.
Order product.sn:9:22: quantity = 'some text value'
^
This is because attribute quantity
is defined in the LDM.sn
as numeric attribute. It should therefore contain only number values. And now we are trying to put a text value inside of a numeric attribute. That is of cours incorrect.
We can of cours change the type of this attribute from number to text by changing quantity : number
to quantity : text
in the LDM.sn
. But that is of course a bit weird. So let's simply ...
- Change all back as it was in the beginning of this section.
8. Conclusion
Many more errors can occur and in the rest of this getting started we will try to cause some more complicated ones as well. But for now, the most common you have seen, and you also know how to solve them, or let XLRIT solve them 😉.
However, resolving errors is often tricky and requires experience to resolve them. I therefore want to ask you to first follow the next parts of the Getting Started to the letter, and after you've made something work start to try to break things by making small changes to the files you create that should make it break and then see what happens. Discover where it breaks, what error do you get, try to understand why it gives that error, and if you do not understand, simply ask an expert why. Also, sometimes you will make a change that you think should result in an error, but it doesn't. Then ask yourself why it does NOT break. And once again: if you are not sure, you can simply ask an expert. We are happy to help.
Next, let's add more and more functionality to this little webshop until it becomes not so little anymore.