It is very likely that your employer will view this failure very seriously and it is likely to have disciplinary consequences, including even dismissal.
For safety-critical roles, you should expect your employer to enforce a policy of 'zero tolerance' of drug or alcohol misuse. Network Rail’s policy is a good example of this: it is a criminal offence for a train driver to be unfit for work due to drink or drugs.
In a good policy, the rules should be clear and well explained and the consequences of breaching the policy should be spelled out.
If you fail a test, there should be a full investigation, following your employer's drug or alcohol testing procedure and their disciplinary procedure. You may have an innocent explanation, such as the presence of prescription drugs.
The TUC says: "Even once a positive result is confirmed, it should not be acted upon until the person who gave the sample has been interviewed by a medical doctor to find out if anything else could have resulted in the positive result."
Drug tests are not infallible. If you have good reason to doubt that the test result is correct, you should ideally ask for access to the test results so that you can have them independently checked and verified. The TUC has put together a lot of useful information on drug and alcohol testing. You can find out more on the TUC Drugs and Alcohol pages.
Employers are supposed to try to approach drug and alcohol issues with compassion and support. In particular, taking drugs or alcohol out of working hours is often linked to work-related stress and an inability to cope. In practice, however, many employers adopt a harsh approach when workers fail drug and alcohol tests.